Examples of LocalContext


Examples of org.jboss.errai.bus.server.util.LocalContext

       * If the message didn't not come from a remote, we don't handle it.
       */
      if (!message.isFlagSet(RoutingFlag.FromRemote))
        return;

      final LocalContext localContext = LocalContext.get(message);

      switch (CDICommands.valueOf(message.getCommandType())) {
        case CDIEvent:
          if (!isRoutable(localContext, message)) {
            return;
          }

          final Object o = message.get(Object.class, CDIProtocol.BeanReference);
          EventConversationContext.activate(o, CDIServerUtil.getSessionId(message));
          try {
            @SuppressWarnings("unchecked")
            final Set<String> qualifierNames = message.get(Set.class, CDIProtocol.Qualifiers);
            List<Annotation> qualifiers = null;
            if (qualifierNames != null) {
              for (String qualifierName : qualifierNames) {
                if (qualifiers == null) {
                  qualifiers = new ArrayList<Annotation>();
                }
                Annotation qualifier = allQualifiers.get(qualifierName);
                if (qualifier != null) {
                  qualifiers.add(qualifier);
                }
              }
            }

            if (qualifiers != null) {
              beanManager.fireEvent(o, qualifiers.toArray(new Annotation[qualifiers.size()]));
            }
            else {
              beanManager.fireEvent(o);
            }
          }
          finally {
            EventConversationContext.deactivate();
          }

          break;

        case AttachRemote:
          MessageBuilder.createConversation(message).toSubject(CDI.CLIENT_DISPATCHER_SUBJECT)
                  .command(BusCommands.RemoteSubscribe)
                  .with(MessageParts.Value, observedEvents.toArray(new String[observedEvents.size()])).done().reply();

          localContext.setAttribute(CDI_EVENT_CHANNEL_OPEN, "1");
          break;

        default:
          throw new IllegalArgumentException("Unknown command type " + message.getCommandType());
      }
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

      if (BusCommand.Associate.name().equals(commandType)) {
        final String sessionKey = ejObject.get(MessageParts.ConnectionSessionKey.name()).isString().stringValue();

        // has this client already attempted a connection, and is in a wait verify state
        if (sessionKey != null && (session = service.getBus().getSessionBySessionId(sessionKey)) != null) {
          final LocalContext localCometSession = LocalContext.get(session);

          if (localCometSession.hasAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS) &&
                  WebSocketServerHandler.WEBSOCKET_ACTIVE.equals(localCometSession.getAttribute(String.class, WebSocketServerHandler.SESSION_ATTR_WS_STATUS))) {

            // set the session queue into direct channel mode.
            final MessageQueue queue = service.getBus().getQueueBySession(sessionKey);
            queue.setDeliveryHandler(DirectDeliveryHandler.createFor(new SimpleEventChannelWrapped(socket)));
            activeChannels.put(socket, session);
            return;
          }

          // check the activation key matches.
          final EJString activationKey = ejObject.get(MessageParts.WebSocketToken.name()).isString();
          if (activationKey == null || !WebSocketTokenManager.verifyOneTimeToken(session, activationKey.stringValue())) {

            // nope. go away!
            sendMessage(new SimpleEventChannelWrapped(socket), getFailedNegotiation("bad negotiation key"));
          }
          else {
            // the key matches. now we send the reverse challenge to prove this client is actually
            // already talking to the bus over the COMET channel.
            final String reverseToken = WebSocketTokenManager.getNewOneTimeToken(session);
            localCometSession.setAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS, WebSocketServerHandler.WEBSOCKET_AWAIT_ACTIVATION);

            // send the challenge.
            sendMessage(new SimpleEventChannelWrapped(socket), getReverseChallenge(reverseToken));
            return;
          }
View Full Code Here

Examples of org.rhq.core.pc.component.ComponentInvocationContextImpl.LocalContext

            this.method = method;
            this.args = args;
            this.lock = lock;
            this.componentInvocationContext = (ComponentInvocationContextImpl) resourceContainer.getResourceContext()
                .getComponentInvocationContext();
            localContext = new LocalContext();
        }
View Full Code Here

Examples of org.rhq.core.pc.component.ComponentInvocationContextImpl.LocalContext

        assertEquals(recorder.getRecordedValue(), false);
    }

    @Test(timeOut = 1000 * 30)
    public void threadShouldSeeLocalContextValue() throws Exception {
        final LocalContext localContext = new LocalContext();
        InterruptedStatusRecorder recorder = new InterruptedStatusRecorder() {
            @Override
            public void run() {
                componentInvocationContext.setLocalContext(localContext);
                while (!componentInvocationContext.isInterrupted()) {
                    try {
                        Thread.sleep(SECONDS.toMillis(1));
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                value = componentInvocationContext.isInterrupted();
            }
        };
        Thread thread = startRecorderThread(recorder);
        localContext.markInterrupted();
        thread.join();
        assertEquals(recorder.getRecordedValue(), true);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.