use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.
the class TransactionalProtocolClientTestCase method createClient.
/**
* 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 ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
final ManagementChannelHandler channelAssociation = new ManagementChannelHandler(strategy, clientExecutor);
final TransactionalProtocolClient client = TransactionalProtocolHandlers.createClient(channelAssociation);
channel.addCloseHandler(channelAssociation);
channel.receiveMessage(channelAssociation.getReceiver());
return client;
}
use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.
the class CLIModelControllerClient method getOrCreateChannel.
protected Channel getOrCreateChannel() throws IOException {
Channel ch = null;
// Strategy is checked against null by mutiple methods in locked blocks.
// Make it non null only at the end of connection process to advertise
// that connection is done.
ManagementClientChannelStrategy localStrategy;
synchronized (lock) {
if (strategy == null) {
final ChannelCloseHandler channelCloseHandler = new ChannelCloseHandler();
localStrategy = ManagementClientChannelStrategy.create(channelConfig, channelAssociation, handler, saslOptions, sslContext, channelCloseHandler);
channelCloseHandler.setOriginalStrategy(localStrategy);
} else {
localStrategy = strategy;
}
state.set(CONNECTING);
}
// Can't be called locked, can create dead-lock in case close occurs.
ch = localStrategy.getChannel();
synchronized (lock) {
strategy = localStrategy;
// the state is switched to MUST_CLOSE.
if (state.get() == MUST_CLOSE) {
close();
lock.notifyAll();
throw new IOException("Connection closed");
}
// in that case the channel close handler would change the state to LOST_CONNECTION
if (state.get() == LOST_CONNECTION) {
// this will clean up things up here but the closed channel is still returned
close();
} else {
state.set(CONNECTED);
}
lock.notifyAll();
}
return ch;
}
use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.
the class ExistingChannelModelControllerClient method createReceiving.
/**
* Create a model controller client which is exclusively receiving messages on an existing channel.
*
* @param channel the channel
* @param executorService an executor
* @return the created client
*/
public static ModelControllerClient createReceiving(final Channel channel, final ExecutorService executorService) {
final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
final ManagementChannelHandler handler = new ManagementChannelHandler(strategy, executorService);
final ExistingChannelModelControllerClient client = new ExistingChannelModelControllerClient(handler);
handler.addHandlerFactory(client);
channel.addCloseHandler(new CloseHandler<Channel>() {
@Override
public void handleClose(Channel closed, IOException exception) {
handler.shutdown();
try {
handler.awaitCompletion(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
handler.shutdownNow();
}
}
});
channel.receiveMessage(handler.getReceiver());
return client;
}
use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.
the class ModelControllerClientTestCase method setupTestClient.
private ModelControllerClient setupTestClient(final ModelController controller) throws IOException {
try {
channels.setupRemoting(new ManagementChannelInitialization() {
@Override
public ManagementChannelHandler startReceiving(Channel channel) {
final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
final ManagementChannelHandler support = new ManagementChannelHandler(strategy, channels.getExecutorService());
support.addHandlerFactory(new ModelControllerClientOperationHandler(controller, support, new ResponseAttachmentInputStreamSupport(), getClientRequestExecutor()));
channel.receiveMessage(support.getReceiver());
return support;
}
private ExecutorService getClientRequestExecutor() {
final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(512);
final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() {
public ThreadFactory run() {
return new JBossThreadFactory(new ThreadGroup("management-handler-thread"), Boolean.FALSE, null, "%G - %t", null, null);
}
});
ThreadPoolExecutor executor = new ThreadPoolExecutor(4, 4, 250L, TimeUnit.MILLISECONDS, workQueue, threadFactory);
// Allow the core threads to time out as well
executor.allowCoreThreadTimeOut(true);
return executor;
}
});
channels.startClientConnetion();
} catch (Exception e) {
throw new RuntimeException(e);
}
final Channel clientChannel = channels.getClientChannel();
return ExistingChannelModelControllerClient.createReceiving(clientChannel, channels.getExecutorService());
}
use of org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy in project wildfly-core by wildfly.
the class RemoteProxyControllerProtocolTestCase method setupProxyHandlers.
private RemoteProxyController setupProxyHandlers(final ModelController proxiedController) {
try {
channels = new RemoteChannelPairSetup();
channels.setupRemoting(new ManagementChannelInitialization() {
@Override
public ManagementChannelHandler startReceiving(Channel channel) {
final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
final ManagementChannelHandler support = new ManagementChannelHandler(strategy, channels.getExecutorService());
support.addHandlerFactory(new TransactionalProtocolOperationHandler(proxiedController, support, responseAttachmentSupport));
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 ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(clientChannel);
final ManagementChannelHandler support = new ManagementChannelHandler(strategy, channels.getExecutorService());
final RemoteProxyController proxyController = RemoteProxyController.create(support, PathAddress.pathAddress(), ProxyOperationAddressTranslator.HOST);
clientChannel.addCloseHandler(new CloseHandler<Channel>() {
@Override
public void handleClose(Channel closed, IOException exception) {
support.shutdownNow();
}
});
clientChannel.receiveMessage(support.getReceiver());
return proxyController;
}
Aggregations