コード例 #1
0
  public ConnectionEntry createConnectionEntry(
      final Acceptor acceptorUsed, final Connection connection) {
    final Configuration config = server.getConfiguration();

    Executor connectionExecutor = server.getExecutorFactory().getExecutor();

    final CoreRemotingConnection rc =
        new RemotingConnectionImpl(
            ServerPacketDecoder.INSTANCE,
            connection,
            incomingInterceptors,
            outgoingInterceptors,
            config.isAsyncConnectionExecutionEnabled() ? connectionExecutor : null,
            server.getNodeID());

    Channel channel1 = rc.getChannel(CHANNEL_ID.SESSION.id, -1);

    ChannelHandler handler = new ActiveMQPacketHandler(this, server, channel1, rc);

    channel1.setHandler(handler);

    long ttl = ActiveMQClient.DEFAULT_CONNECTION_TTL;

    if (config.getConnectionTTLOverride() != -1) {
      ttl = config.getConnectionTTLOverride();
    }

    final ConnectionEntry entry =
        new ConnectionEntry(rc, connectionExecutor, System.currentTimeMillis(), ttl);

    final Channel channel0 = rc.getChannel(ChannelImpl.CHANNEL_ID.PING.id, -1);

    channel0.setHandler(new LocalChannelHandler(config, entry, channel0, acceptorUsed, rc));

    server
        .getClusterManager()
        .addClusterChannelHandler(
            rc.getChannel(CHANNEL_ID.CLUSTER.id, -1), acceptorUsed, rc, server.getActivation());

    return entry;
  }
コード例 #2
0
  private void handleCreateSession(final CreateSessionMessage request) {
    boolean incompatibleVersion = false;
    Packet response;
    try {
      Version version = server.getVersion();
      if (!version.isCompatible(request.getVersion())) {
        throw ActiveMQMessageBundle.BUNDLE.incompatibleClientServer();
      }

      if (!server.isStarted()) {
        throw ActiveMQMessageBundle.BUNDLE.serverNotStarted();
      }

      // XXX HORNETQ-720 Taylor commented out this test. Should be verified.
      /*if (!server.checkActivate())
      {
         throw new ActiveMQException(ActiveMQException.SESSION_CREATION_REJECTED,
                                    "Server will not accept create session requests");
      }*/

      if (connection.getClientVersion() == 0) {
        connection.setClientVersion(request.getVersion());
      } else if (connection.getClientVersion() != request.getVersion()) {
        ActiveMQServerLogger.LOGGER.incompatibleVersionAfterConnect(
            request.getVersion(), connection.getClientVersion());
      }

      Channel channel =
          connection.getChannel(request.getSessionChannelID(), request.getWindowSize());

      ActiveMQPrincipal activeMQPrincipal = null;

      if (request.getUsername() == null) {
        activeMQPrincipal = connection.getDefaultActiveMQPrincipal();
      }

      ServerSession session =
          server.createSession(
              request.getName(),
              activeMQPrincipal == null ? request.getUsername() : activeMQPrincipal.getUserName(),
              activeMQPrincipal == null ? request.getPassword() : activeMQPrincipal.getPassword(),
              request.getMinLargeMessageSize(),
              connection,
              request.isAutoCommitSends(),
              request.isAutoCommitAcks(),
              request.isPreAcknowledge(),
              request.isXA(),
              request.getDefaultAddress(),
              new CoreSessionCallback(request.getName(), protocolManager, channel, connection),
              true);

      ServerSessionPacketHandler handler =
          new ServerSessionPacketHandler(session, server.getStorageManager(), channel);
      channel.setHandler(handler);

      // TODO - where is this removed?
      protocolManager.addSessionHandler(request.getName(), handler);

      response = new CreateSessionResponseMessage(server.getVersion().getIncrementingVersion());
    } catch (ActiveMQException e) {
      if (e.getType() == ActiveMQExceptionType.INCOMPATIBLE_CLIENT_SERVER_VERSIONS) {
        incompatibleVersion = true;
        logger.debug("Sending ActiveMQException after Incompatible client", e);
      } else {
        ActiveMQServerLogger.LOGGER.failedToCreateSession(e);
      }

      response = new ActiveMQExceptionMessage(e);
    } catch (Exception e) {
      ActiveMQServerLogger.LOGGER.failedToCreateSession(e);

      response = new ActiveMQExceptionMessage(new ActiveMQInternalErrorException());
    }

    // send the exception to the client and destroy
    // the connection if the client and server versions
    // are not compatible
    if (incompatibleVersion) {
      channel1.sendAndFlush(response);
    } else {
      channel1.send(response);
    }
  }