use of com.automatak.dnp3.Channel 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 com.automatak.dnp3.Channel 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 com.automatak.dnp3.Channel in project wildfly-core by wildfly.
the class RemotingModelControllerClient method getOrCreateChannel.
protected Channel getOrCreateChannel() throws IOException {
synchronized (closeable) {
if (closeable.closed) {
throw ControllerClientLogger.ROOT_LOGGER.objectIsClosed(ModelControllerClient.class.getSimpleName());
}
if (closeable.strategy == null) {
try {
closeable.endpoint = Endpoint.builder().setEndpointName("management-client").build();
final ProtocolConnectionConfiguration configuration = ProtocolConfigurationFactory.create(closeable.clientConfiguration, closeable.endpoint);
closeable.strategy = ManagementClientChannelStrategy.create(configuration, closeable.channelAssociation, closeable.clientConfiguration.getCallbackHandler(), closeable.clientConfiguration.getSaslOptions(), closeable.clientConfiguration.getSSLContext(), new CloseHandler<Channel>() {
@Override
public void handleClose(final Channel closed, final IOException exception) {
closeable.channelAssociation.handleChannelClosed(closed, exception);
}
});
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return closeable.strategy.getChannel();
}
}
use of com.automatak.dnp3.Channel 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 com.automatak.dnp3.Channel in project wildfly-core by wildfly.
the class RemoteChannelPairSetup method setupRemoting.
public void setupRemoting(final ManagementMessageHandler handler) throws IOException {
// executorService = new ThreadPoolExecutor(16, 16, 1L, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>());
ThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("Remoting"), Boolean.FALSE, null, "Remoting %f thread %t", null, null);
executorService = new QueueExecutor(EXECUTOR_MAX_THREADS / 4 + 1, EXECUTOR_MAX_THREADS, EXECUTOR_KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS, 500, threadFactory, true, null);
ChannelServer.Configuration configuration = new ChannelServer.Configuration();
configuration.setEndpointName(ENDPOINT_NAME);
configuration.setUriScheme(URI_SCHEME);
configuration.setBindAddress(new InetSocketAddress("127.0.0.1", PORT));
configuration.setExecutor(executorService);
channelServer = ChannelServer.create(configuration);
final Channel.Receiver receiver = ManagementChannelReceiver.createDelegating(handler);
this.registration = channelServer.addChannelOpenListener(TEST_CHANNEL, new OpenListener() {
@Override
public void registrationTerminated() {
}
@Override
public void channelOpened(Channel channel) {
serverChannel = channel;
serverChannel.receiveMessage(receiver);
clientConnectedLatch.countDown();
}
});
}
Aggregations