예제 #1
0
  @Override
  public ProxyController serverCommunicationRegistered(
      final String serverProcessName, final ManagementChannelHandler channelAssociation) {
    if (shutdown || connectionFinished) {
      throw HostControllerMessages.MESSAGES.hostAlreadyShutdown();
    }
    final String serverName = ManagedServer.getServerName(serverProcessName);
    final ManagedServer server = servers.get(serverName);
    if (server == null) {
      ROOT_LOGGER.noServerAvailable(serverName);
      return null;
    }
    try {
      final TransactionalProtocolClient client = server.channelRegistered(channelAssociation);
      final Channel channel = channelAssociation.getChannel();
      channel.addCloseHandler(
          new CloseHandler<Channel>() {

            public void handleClose(final Channel closed, final IOException exception) {
              final boolean shuttingDown = shutdown || connectionFinished;
              // Unregister right away
              if (server.callbackUnregistered(client, shuttingDown)) {
                domainController.unregisterRunningServer(server.getServerName());
              }
            }
          });
      return server.getProxyController();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  public void startReceiving() {
    final Channel channel = this.channelAssociation.getChannel();
    channel.addCloseHandler(new ChannelCloseHandler());

    channel.receiveMessage(this);
    // listen to module availability/unavailability events
    this.deploymentRepository.addListener(this);
    // listen to new clusters (a.k.a groups) being started/stopped
    this.clientMappingRegistryCollector.addListener(this);
    // Send the cluster topology for existing clusters in the registry
    // and for each of these clusters added ourselves as a listener for cluster
    // topology changes (members added/removed events in the cluster)
    final Collection<Registry<String, List<ClientMapping>>> clusters =
        this.clientMappingRegistryCollector.getRegistries();
    try {
      this.sendNewClusterFormedMessage(clusters);
    } catch (IOException ioe) {
      // just log and don't throw an error
      EjbLogger.ROOT_LOGGER.failedToSendClusterFormationMessageToClient(ioe, channel);
    }
    for (final Registry<String, List<ClientMapping>> cluster : clusters) {
      // add the topology update listener
      final ClusterTopologyUpdateListener clusterTopologyUpdateListener =
          new ClusterTopologyUpdateListener(cluster, this);
      cluster.addListener(clusterTopologyUpdateListener);

      // keep track of this topology update listener so that we can unregister it when the channel
      // is closed and
      // we no longer are interested in the topology updates
      this.clusterTopologyUpdateListeners.add(clusterTopologyUpdateListener);
    }
  }
 /**
  * Create the protocol client to talk to the remote controller.
  *
  * @param channel the remoting channel
  * @return the client
  * @throws Exception
  */
 TransactionalProtocolClient createClient(final Channel channel) {
   channels.add(channel);
   final ManagementChannelHandler channelAssociation =
       new ManagementChannelHandler(channel, clientExecutor);
   final TransactionalProtocolClient client =
       TransactionalProtocolHandlers.createClient(channelAssociation);
   channel.addCloseHandler(channelAssociation);
   channel.receiveMessage(channelAssociation.getReceiver());
   return client;
 }
예제 #4
0
  @Override
  protected ProxyController createProxyController(
      final ModelController proxiedController, final PathAddress proxyNodeAddress) {
    try {
      channels = new RemoteChannelPairSetup();
      channels.setupRemoting(
          new ManagementChannelInitialization() {
            @Override
            public ManagementChannelHandler startReceiving(Channel channel) {
              final ManagementChannelHandler support =
                  new ManagementChannelHandler(channel, channels.getExecutorService());
              support.addHandlerFactory(
                  new TransactionalProtocolOperationHandler(proxiedController, support));
              channel.addCloseHandler(
                  new CloseHandler<Channel>() {
                    @Override
                    public void handleClose(Channel closed, IOException exception) {
                      support.shutdownNow();
                    }
                  });
              channel.receiveMessage(support.getReceiver());
              return support;
            }
          });
      channels.startClientConnetion();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    final Channel clientChannel = channels.getClientChannel();
    final ManagementChannelHandler support =
        new ManagementChannelHandler(clientChannel, channels.getExecutorService());
    final RemoteProxyController proxyController =
        RemoteProxyController.create(
            support, proxyNodeAddress, ProxyOperationAddressTranslator.SERVER);
    clientChannel.addCloseHandler(
        new CloseHandler<Channel>() {
          @Override
          public void handleClose(Channel closed, IOException exception) {
            support.shutdownNow();
          }
        });
    clientChannel.receiveMessage(support.getReceiver());
    return proxyController;
  }
 @Override
 public void connectionOpened(final Connection connection) throws IOException {
   final Channel channel =
       openChannel(connection, CHANNEL_SERVICE_TYPE, configuration.getOptionMap());
   if (setChannel(channel)) {
     channel.receiveMessage(channelHandler.getReceiver());
     channel.addCloseHandler(channelHandler);
     try {
       // Start the registration process
       channelHandler.executeRequest(new RegisterHostControllerRequest(), null).getResult().get();
     } catch (Exception e) {
       if (e.getCause() instanceof IOException) {
         throw (IOException) e.getCause();
       }
       throw new IOException(e);
     }
     // Registered
     registered();
   } else {
     channel.closeAsync();
   }
 }
 @Override
 public Channel.Key startReceiving(final Channel channel) {
   final ManagementChannelHandler handler =
       new ManagementChannelHandler(
           ManagementClientChannelStrategy.create(channel), getExecutor());
   // Assemble the request handlers for the domain channel
   handler.addHandlerFactory(
       new HostControllerRegistrationHandler(handler, getController(), domainController));
   handler.addHandlerFactory(new ModelControllerClientOperationHandler(getController(), handler));
   handler.addHandlerFactory(new MasterDomainControllerOperationHandlerImpl(domainController));
   final Channel.Key key =
       channel.addCloseHandler(
           new CloseHandler<Channel>() {
             @Override
             public void handleClose(Channel closed, IOException exception) {
               handler.shutdown();
               boolean interrupted = false;
               try {
                 if (!handler.awaitCompletion(CHANNEL_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS)) {
                   ROOT_LOGGER.gracefulManagementChannelHandlerShutdownTimedOut(
                       CHANNEL_SHUTDOWN_TIMEOUT);
                 }
               } catch (InterruptedException e) {
                 interrupted = true;
                 ROOT_LOGGER.serviceShutdownIncomplete(e);
               } catch (Exception e) {
                 ROOT_LOGGER.serviceShutdownIncomplete(e);
               } finally {
                 handler.shutdownNow();
                 if (interrupted) {
                   Thread.currentThread().interrupt();
                 }
               }
             }
           });
   channel.receiveMessage(handler.getReceiver());
   return key;
 }
 @Override
 public synchronized ProxyController popChannelAndCreateProxy(final String hostName) {
   final Channel channel = unregisteredHostChannels.remove(hostName);
   if (channel == null) {
     throw new IllegalArgumentException("No channel for host " + hostName);
   }
   channel.addCloseHandler(
       new CloseHandler<Channel>() {
         public void handleClose(final Channel closed, final IOException exception) {
           unregisterRemoteHost(hostName);
         }
       });
   final PathAddress addr =
       PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.HOST, hostName));
   RemoteProxyController proxy =
       RemoteProxyController.create(
           proxyExecutor, addr, ProxyOperationAddressTranslator.HOST, channel);
   ProxyCreatedCallback callback = proxyCreatedCallbacks.remove(hostName);
   if (callback != null) {
     callback.proxyCreated(proxy);
   }
   return proxy;
 }
  @Override
  public synchronized void registerChannel(
      final String hostName, final Channel channel, final ProxyCreatedCallback callback) {

    /* Disable this as part of the REM3-121 workarounds
    PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(HOST, hostName));
    if (modelNodeRegistration.getProxyController(addr) != null) {
        throw new IllegalArgumentException("There is already a registered slave named '" + hostName + "'");
    }
    */
    if (unregisteredHostChannels.containsKey(hostName)) {
      throw new IllegalArgumentException("Already have a connection for host " + hostName);
    }
    unregisteredHostChannels.put(hostName, channel);
    proxyCreatedCallbacks.put(hostName, callback);
    channel.addCloseHandler(
        new CloseHandler<Channel>() {
          public void handleClose(final Channel closed, final IOException exception) {
            unregisteredHostChannels.remove(hostName);
            proxyCreatedCallbacks.remove(hostName);
          }
        });
  }