Search in sources :

Example 1 with WorkContextEntryImpl

use of org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntryImpl in project Payara by payara.

the class WorkContextLocalMap method put.

// Implementation of weblogic.workarea.WorkContextMap
@SuppressWarnings("unchecked")
public WorkContext put(String key, WorkContext workContext, int propagationMode) throws PropertyReadOnlyException {
    if (debugWorkContext.isLoggable(Level.FINEST)) {
        debugWorkContext.log(Level.FINEST, "put(" + key + ", " + workContext + ")");
    }
    if (key == null || key.equals("")) {
        throw new NullPointerException("Cannot use null key");
    }
    if (workContext == null) {
        throw new NullPointerException("Cannot use null WorkContext");
    }
    WorkContextEntry wce = (WorkContextEntry) map.get(key);
    if (wce != null) {
        // Can't modify read-only properties
        if (!WorkContextAccessController.isAccessAllowed(key, WorkContextAccessController.UPDATE)) {
            throw new PropertyReadOnlyException(key);
        }
    } else if (!WorkContextAccessController.isAccessAllowed(key, WorkContextAccessController.CREATE)) {
        throw new AccessControlException("No CREATE permission for key: \"" + key + "\"");
    }
    // Replace whatever is there.
    map.put(key, new WorkContextEntryImpl(key, workContext, propagationMode));
    version++;
    return wce == null ? null : wce.getWorkContext();
}
Also used : AccessControlException(java.security.AccessControlException) WorkContextEntryImpl(org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntryImpl) WorkContextEntry(org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntry)

Example 2 with WorkContextEntryImpl

use of org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntryImpl in project Payara by payara.

the class WorkContextLocalMap method receiveResponse.

@SuppressWarnings("unchecked")
public void receiveResponse(WorkContextInput in) throws IOException {
    HashSet<String> propKeySet = new HashSet<String>();
    // should come back in the response.
    synchronized (map) {
        for (Iterator<WorkContextEntry> i = map.values().iterator(); i.hasNext(); ) {
            WorkContextEntry wce = (WorkContextEntry) i.next();
            int propMode = wce.getPropagationMode();
            // If PropagationMode is "not" ONEWAY and LOCAL, remove the entry
            if (((propMode & PropagationMode.ONEWAY) == 0) && ((propMode & PropagationMode.LOCAL) == 0)) {
                propKeySet.add(wce.getName());
                i.remove();
                version++;
            }
        }
    }
    // Nothing is as nothing does.
    if (in == null) {
        return;
    }
    // properties.
    while (true) {
        try {
            WorkContextEntry wce = WorkContextEntryImpl.readEntry(in);
            version++;
            if (wce == WorkContextEntry.NULL_CONTEXT) {
                break;
            }
            if (propKeySet.contains(wce.getName())) {
                // this allows the caller to remain the originator of the properties.
                map.put(wce.getName(), new WorkContextEntryImpl(wce.getName(), wce.getWorkContext(), wce.getPropagationMode()));
            } else {
                map.put(wce.getName(), wce);
            }
        } catch (ClassNotFoundException cnfe) {
            if (debugWorkContext.isLoggable(Level.FINEST)) {
                debugWorkContext.log(Level.FINEST, "receiveResponse : ", cnfe);
            }
        // Ignored and proceed with other entries
        // FIX ME andyp 19-Aug-08 -- need to log this failure.
        }
    }
}
Also used : WorkContextEntryImpl(org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntryImpl) WorkContextEntry(org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntry) HashSet(java.util.HashSet)

Aggregations

WorkContextEntry (org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntry)2 WorkContextEntryImpl (org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntryImpl)2 AccessControlException (java.security.AccessControlException)1 HashSet (java.util.HashSet)1