Ejemplo n.º 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(
            connection,
            interceptors,
            config.isAsyncConnectionExecutionEnabled() ? connectionExecutor : null,
            server.getNodeID());

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

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

    channel1.setHandler(handler);

    long ttl = HornetQClient.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(0, -1);

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

    return entry;
  }
Ejemplo n.º 2
0
    public void handlePacket(final Packet packet) {
      if (packet.getType() == PacketImpl.PING) {
        Ping ping = (Ping) packet;

        if (config.getConnectionTTLOverride() == -1) {
          // Allow clients to specify connection ttl
          entry.ttl = ping.getConnectionTTL();
        }

        // Just send a ping back
        channel0.send(packet);
      } else if (packet.getType() == PacketImpl.SUBSCRIBE_TOPOLOGY
          || packet.getType() == PacketImpl.SUBSCRIBE_TOPOLOGY_V2) {
        SubscribeClusterTopologyUpdatesMessage msg =
            (SubscribeClusterTopologyUpdatesMessage) packet;

        if (packet.getType() == PacketImpl.SUBSCRIBE_TOPOLOGY_V2) {
          channel0
              .getConnection()
              .setClientVersion(
                  ((SubscribeClusterTopologyUpdatesMessageV2) msg).getClientVersion());
        }

        final ClusterTopologyListener listener =
            new ClusterTopologyListener() {
              public void nodeUP(
                  final long uniqueEventID,
                  final String nodeID,
                  final Pair<TransportConfiguration, TransportConfiguration> connectorPair,
                  final boolean last) {
                // Using an executor as most of the notifications on the Topology
                // may come from a channel itself
                // What could cause deadlocks
                entry.connectionExecutor.execute(
                    new Runnable() {
                      public void run() {
                        if (channel0.supports(PacketImpl.CLUSTER_TOPOLOGY_V2)) {
                          channel0.send(
                              new ClusterTopologyChangeMessage_V2(
                                  uniqueEventID, nodeID, connectorPair, last));
                        } else {
                          channel0.send(
                              new ClusterTopologyChangeMessage(nodeID, connectorPair, last));
                        }
                      }
                    });
              }

              public void nodeDown(final long uniqueEventID, final String nodeID) {
                // Using an executor as most of the notifications on the Topology
                // may come from a channel itself
                // What could cause deadlocks
                entry.connectionExecutor.execute(
                    new Runnable() {
                      public void run() {
                        if (channel0.supports(PacketImpl.CLUSTER_TOPOLOGY_V2)) {
                          channel0.send(new ClusterTopologyChangeMessage_V2(uniqueEventID, nodeID));
                        } else {
                          channel0.send(new ClusterTopologyChangeMessage(nodeID));
                        }
                      }
                    });
              }

              @Override
              public String toString() {
                return "Remote Proxy on channel "
                    + Integer.toHexString(System.identityHashCode(this));
              }
            };

        if (acceptorUsed.getClusterConnection() != null) {
          acceptorUsed.getClusterConnection().addClusterTopologyListener(listener);

          rc.addCloseListener(
              new CloseListener() {
                public void connectionClosed() {
                  acceptorUsed.getClusterConnection().removeClusterTopologyListener(listener);
                }
              });
        } else {
          // if not clustered, we send a single notification to the client containing the node-id
          // where the server is connected to
          // This is done this way so Recovery discovery could also use the node-id for
          // non-clustered setups
          entry.connectionExecutor.execute(
              new Runnable() {
                public void run() {
                  String nodeId = server.getNodeID().toString();
                  Pair<TransportConfiguration, TransportConfiguration> emptyConfig =
                      new Pair<TransportConfiguration, TransportConfiguration>(null, null);
                  if (channel0.supports(PacketImpl.CLUSTER_TOPOLOGY_V2)) {
                    channel0.send(
                        new ClusterTopologyChangeMessage_V2(
                            System.currentTimeMillis(), nodeId, emptyConfig, true));
                  } else {
                    channel0.send(new ClusterTopologyChangeMessage(nodeId, emptyConfig, true));
                  }
                }
              });
        }
      } else if (packet.getType() == PacketImpl.NODE_ANNOUNCE) {
        NodeAnnounceMessage msg = (NodeAnnounceMessage) packet;

        Pair<TransportConfiguration, TransportConfiguration> pair;
        if (msg.isBackup()) {
          pair = new Pair<TransportConfiguration, TransportConfiguration>(null, msg.getConnector());
        } else {
          pair =
              new Pair<TransportConfiguration, TransportConfiguration>(
                  msg.getConnector(), msg.getBackupConnector());
        }
        if (isTrace) {
          HornetQLogger.LOGGER.trace(
              "Server "
                  + server
                  + " receiving nodeUp from NodeID="
                  + msg.getNodeID()
                  + ", pair="
                  + pair);
        }

        if (acceptorUsed != null) {
          ClusterConnection clusterConn = acceptorUsed.getClusterConnection();
          if (clusterConn != null) {
            clusterConn.nodeAnnounced(
                msg.getCurrentEventID(), msg.getNodeID(), pair, msg.isBackup());
          } else {
            HornetQLogger.LOGGER.debug("Cluster connection is null on acceptor = " + acceptorUsed);
          }
        } else {
          HornetQLogger.LOGGER.debug(
              "there is no acceptor used configured at the CoreProtocolManager " + this);
        }
      } else if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) {
        BackupRegistrationMessage msg = (BackupRegistrationMessage) packet;
        ClusterConnection clusterConnection = acceptorUsed.getClusterConnection();

        if (clusterConnection.verify(msg.getClusterUser(), msg.getClusterPassword())) {
          try {
            server.startReplication(
                rc, clusterConnection, getPair(msg.getConnector(), true), msg.isFailBackRequest());
          } catch (HornetQException e) {
            channel0.send(new BackupRegistrationFailedMessage(e));
          }
        } else {
          channel0.send(new BackupRegistrationFailedMessage(null));
        }
      }
    }
  public void testGetAttributes() throws Exception {
    HornetQServerControl serverControl = createManagementControl();

    Assert.assertEquals(server.getVersion().getFullVersion(), serverControl.getVersion());

    Assert.assertEquals(conf.isClustered(), serverControl.isClustered());
    Assert.assertEquals(
        conf.isPersistDeliveryCountBeforeDelivery(),
        serverControl.isPersistDeliveryCountBeforeDelivery());
    Assert.assertEquals(conf.isBackup(), serverControl.isBackup());
    Assert.assertEquals(conf.isSharedStore(), serverControl.isSharedStore());
    Assert.assertEquals(
        conf.getScheduledThreadPoolMaxSize(), serverControl.getScheduledThreadPoolMaxSize());
    Assert.assertEquals(conf.getThreadPoolMaxSize(), serverControl.getThreadPoolMaxSize());
    Assert.assertEquals(
        conf.getSecurityInvalidationInterval(), serverControl.getSecurityInvalidationInterval());
    Assert.assertEquals(conf.isSecurityEnabled(), serverControl.isSecurityEnabled());
    Assert.assertEquals(
        conf.isAsyncConnectionExecutionEnabled(),
        serverControl.isAsyncConnectionExecutionEnabled());
    Assert.assertEquals(
        conf.getInterceptorClassNames().size(), serverControl.getInterceptorClassNames().length);
    Assert.assertEquals(conf.getConnectionTTLOverride(), serverControl.getConnectionTTLOverride());
    // Assert.assertEquals(conf.getBackupConnectorName(), serverControl.getBackupConnectorName());
    Assert.assertEquals(
        conf.getManagementAddress().toString(), serverControl.getManagementAddress());
    Assert.assertEquals(
        conf.getManagementNotificationAddress().toString(),
        serverControl.getManagementNotificationAddress());
    Assert.assertEquals(conf.getIDCacheSize(), serverControl.getIDCacheSize());
    Assert.assertEquals(conf.isPersistIDCache(), serverControl.isPersistIDCache());
    Assert.assertEquals(conf.getBindingsDirectory(), serverControl.getBindingsDirectory());
    Assert.assertEquals(conf.getJournalDirectory(), serverControl.getJournalDirectory());
    Assert.assertEquals(conf.getJournalType().toString(), serverControl.getJournalType());
    Assert.assertEquals(
        conf.isJournalSyncTransactional(), serverControl.isJournalSyncTransactional());
    Assert.assertEquals(
        conf.isJournalSyncNonTransactional(), serverControl.isJournalSyncNonTransactional());
    Assert.assertEquals(conf.getJournalFileSize(), serverControl.getJournalFileSize());
    Assert.assertEquals(conf.getJournalMinFiles(), serverControl.getJournalMinFiles());
    if (AsynchronousFileImpl.isLoaded()) {
      Assert.assertEquals(conf.getJournalMaxIO_AIO(), serverControl.getJournalMaxIO());
      Assert.assertEquals(conf.getJournalBufferSize_AIO(), serverControl.getJournalBufferSize());
      Assert.assertEquals(
          conf.getJournalBufferTimeout_AIO(), serverControl.getJournalBufferTimeout());
    }
    Assert.assertEquals(conf.isCreateBindingsDir(), serverControl.isCreateBindingsDir());
    Assert.assertEquals(conf.isCreateJournalDir(), serverControl.isCreateJournalDir());
    Assert.assertEquals(conf.getPagingDirectory(), serverControl.getPagingDirectory());
    Assert.assertEquals(
        conf.getLargeMessagesDirectory(), serverControl.getLargeMessagesDirectory());
    Assert.assertEquals(conf.isWildcardRoutingEnabled(), serverControl.isWildcardRoutingEnabled());
    Assert.assertEquals(conf.getTransactionTimeout(), serverControl.getTransactionTimeout());
    Assert.assertEquals(conf.isMessageCounterEnabled(), serverControl.isMessageCounterEnabled());
    Assert.assertEquals(
        conf.getTransactionTimeoutScanPeriod(), serverControl.getTransactionTimeoutScanPeriod());
    Assert.assertEquals(
        conf.getMessageExpiryScanPeriod(), serverControl.getMessageExpiryScanPeriod());
    Assert.assertEquals(
        conf.getMessageExpiryThreadPriority(), serverControl.getMessageExpiryThreadPriority());
    Assert.assertEquals(
        conf.getJournalCompactMinFiles(), serverControl.getJournalCompactMinFiles());
    Assert.assertEquals(
        conf.getJournalCompactPercentage(), serverControl.getJournalCompactPercentage());
    Assert.assertEquals(conf.isPersistenceEnabled(), serverControl.isPersistenceEnabled());
    Assert.assertEquals(
        conf.isFailoverOnServerShutdown(), serverControl.isFailoverOnServerShutdown());
  }