Search in sources :

Example 1 with WorkContextEntry

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

the class WorkContextLocalMap method remove.

public WorkContext remove(String key) throws NoWorkContextException, PropertyReadOnlyException {
    if (debugWorkContext.isLoggable(Level.FINEST)) {
        debugWorkContext.log(Level.FINEST, "remove(" + key + ")");
    }
    WorkContextEntry wce = getEntry(key);
    if (wce == WorkContextEntry.NULL_CONTEXT) {
        throw new NoWorkContextException(key);
    } else if (!wce.isOriginator() && !WorkContextAccessController.isAccessAllowed(key, WorkContextAccessController.DELETE)) {
        throw new PropertyReadOnlyException("No DELETE permission for key: \"" + key + "\"");
    } else {
        map.remove(key);
    }
    version++;
    return wce.getWorkContext();
}
Also used : WorkContextEntry(org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntry)

Example 2 with WorkContextEntry

use of org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntry 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 3 with WorkContextEntry

use of org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntry 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)

Example 4 with WorkContextEntry

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

the class WorkContextLocalMap method copyThreadContexts.

@SuppressWarnings("unchecked")
public WorkContextMapInterceptor copyThreadContexts(int mode) {
    if (map.isEmpty()) {
        return null;
    }
    WorkContextLocalMap copy = new WorkContextLocalMap();
    copy.map.putAll(map);
    copy.version = version;
    for (Iterator<WorkContextEntry> i = copy.map.values().iterator(); i.hasNext(); ) {
        WorkContextEntry e = (WorkContextEntry) i.next();
        if ((e.getPropagationMode() & mode) == 0) {
            i.remove();
        }
        if (debugWorkContext.isLoggable(Level.FINEST)) {
            debugWorkContext.log(Level.FINEST, "copyThreadContexts(" + e.toString() + ")");
        }
    }
    if (copy.map.isEmpty()) {
        return null;
    } else {
        return copy;
    }
}
Also used : WorkContextEntry(org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntry)

Example 5 with WorkContextEntry

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

the class WorkContextLocalMap method receiveRequest.

@SuppressWarnings("unchecked")
public void receiveRequest(WorkContextInput in) throws IOException {
    while (true) {
        try {
            WorkContextEntry wce = WorkContextEntryImpl.readEntry(in);
            if (wce == WorkContextEntry.NULL_CONTEXT) {
                break;
            }
            String key = wce.getName();
            map.put(key, wce);
            if (debugWorkContext.isLoggable(Level.FINEST)) {
                debugWorkContext.log(Level.FINEST, "receiveRequest(" + wce.toString() + ")");
            }
        } catch (ClassNotFoundException cnfe) {
            if (debugWorkContext.isLoggable(Level.FINEST)) {
                debugWorkContext.log(Level.FINEST, "receiveRequest : ", cnfe);
            }
        // Ignored and proceed with other entries
        // FIX ME andyp 19-Aug-08 -- need to log this failure.
        }
    }
}
Also used : WorkContextEntry(org.glassfish.contextpropagation.weblogic.workarea.spi.WorkContextEntry)

Aggregations

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