Search in sources :

Example 1 with ContextMapAdditionalAccessors

use of org.glassfish.contextpropagation.internal.Utils.ContextMapAdditionalAccessors in project Payara by payara.

the class BootstrapUtils method populateMap.

public static void populateMap() throws InsufficientCredentialException {
    ContextMap wcMap = ContextMapHelper.getScopeAwareContextMap();
    wcMap.put("true", true, PropagationMode.defaultSet());
    wcMap.put("string", "string", PropagationMode.defaultSet());
    wcMap.put("one", 1L, PropagationMode.defaultSet());
    ((ContextMapAdditionalAccessors) wcMap).putAscii("ascii", "ascii", PropagationMode.defaultSet());
    ((ContextMapAdditionalAccessors) wcMap).putSerializable("serializable", new HashSet<String>(Arrays.asList("foo")), PropagationMode.defaultSet());
    wcMap.put("byte", (byte) 'b', PropagationMode.defaultSet());
    // View Capable Stuff
    // 1 - Create the factory (assumes that you have already created a ViewCapable class
    ContextViewFactory viewCapableFactory = new ContextViewFactory() {

        @Override
        public ViewCapable createInstance(View view) {
            return new MyViewCapable(view);
        }

        @Override
        public EnumSet<PropagationMode> getPropagationModes() {
            return PropagationMode.defaultSet();
        }
    };
    // 2 - Register the factory
    ContextMapHelper.registerContextFactoryForPrefixNamed("view capable", viewCapableFactory);
    // 3 - Create the ViewCapable instance
    wcMap.createViewCapable("view capable");
    assertEquals("a value", ((MyViewCapable) wcMap.get("view capable")).getValue());
    wcMap.get("ascii");
}
Also used : ContextViewFactory(org.glassfish.contextpropagation.ContextViewFactory) ContextMapAdditionalAccessors(org.glassfish.contextpropagation.internal.Utils.ContextMapAdditionalAccessors) View(org.glassfish.contextpropagation.View) PropagationMode(org.glassfish.contextpropagation.PropagationMode) ContextMap(org.glassfish.contextpropagation.ContextMap)

Aggregations

ContextMap (org.glassfish.contextpropagation.ContextMap)1 ContextViewFactory (org.glassfish.contextpropagation.ContextViewFactory)1 PropagationMode (org.glassfish.contextpropagation.PropagationMode)1 View (org.glassfish.contextpropagation.View)1 ContextMapAdditionalAccessors (org.glassfish.contextpropagation.internal.Utils.ContextMapAdditionalAccessors)1