use of com.automatak.dnp3.Channel in project kubernetes-client by fabric8io.
the class ChannelTest method get.
@Test
void get() {
// Given
server.expect().get().withPath("/apis/apps.open-cluster-management.io/v1/namespaces/ns1/channels/test-get").andReturn(HttpURLConnection.HTTP_OK, createNewChannel("test-get")).once();
// When
Channel channel = client.apps().channels().inNamespace("ns1").withName("test-get").get();
// Then
assertThat(channel).isNotNull().hasFieldOrPropertyWithValue("metadata.name", "test-get");
}
use of com.automatak.dnp3.Channel in project solarnetwork-node by SolarNetwork.
the class MasterDemo method run.
static void run(DNP3Manager manager) throws Exception {
// Create a tcp channel class that will connect to the loopback
Channel channel = manager.addTCPClient("client", LogMasks.NORMAL | LogMasks.APP_COMMS, ChannelRetry.getDefault(), "127.0.0.1", "0.0.0.0", 20000, new Slf4jChannelListener());
// You can modify the defaults to change the way the master behaves
MasterStackConfig config = new MasterStackConfig();
// Create a master instance, pass in a simple singleton to print received values to the console
Master master = channel.addMaster("master", PrintingSOEHandler.getInstance(), DefaultMasterApplication.getInstance(), config);
// do an integrity scan every 2 seconds
// master.addPeriodicScan(Duration.ofSeconds(2), Header.getIntegrity());
master.enable();
// all this cruft just to read a line of text in Java. Oh the humanity.
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
while (true) {
System.out.println("Enter something to issue a command or type <quit> to exit");
String line = in.readLine();
switch(line) {
case ("quit"):
return;
case ("crob"):
ControlRelayOutputBlock crob = new ControlRelayOutputBlock(ControlCode.LATCH_ON, (short) 1, 100, 100, CommandStatus.SUCCESS);
master.selectAndOperateCROB(crob, 0).thenAccept(// asynchronously print the result of the command operation
(CommandTaskResult result) -> System.out.println(result));
break;
case ("scan"):
master.scan(Header.getEventClasses());
break;
default:
System.out.println("Unknown command: " + line);
break;
}
}
}
use of com.automatak.dnp3.Channel in project solarnetwork-node by SolarNetwork.
the class OutstationService method createOutstation.
private Outstation createOutstation() {
Channel channel = channel();
if (channel == null) {
log.info("DNP3 channel not available for outstation [{}]", getUid());
return null;
}
log.info("Initializing DNP3 outstation [{}]", getUid());
try {
return channel.addOutstation(getUid(), commandHandler, app, createOutstationStackConfig());
} catch (DNP3Exception e) {
log.error("Error creating outstation application [{}]: {}", getUid(), e.getMessage(), e);
return null;
}
}
use of com.automatak.dnp3.Channel in project jboss-remoting by jboss-remoting.
the class ChannelTestBase method testWriteCancel.
public void testWriteCancel(final byte[] data) throws IOException, InterruptedException {
final AtomicBoolean wasOk = new AtomicBoolean();
final AtomicReference<IOException> exRef = new AtomicReference<IOException>();
final CountDownLatch latch = new CountDownLatch(1);
recvChannel.receiveMessage(new Channel.Receiver() {
public void handleError(final Channel channel, final IOException error) {
error.printStackTrace();
exRef.set(error);
latch.countDown();
}
public void handleEnd(final Channel channel) {
System.out.println("End of channel");
latch.countDown();
}
public void handleMessage(final Channel channel, final MessageInputStream message) {
new Thread(new Runnable() {
public void run() {
final byte[] received = new byte[TEST_FILE_LENGTH];
int c = 0;
try {
System.out.println("Message received");
int r;
do {
r = message.read(received, c, TEST_FILE_LENGTH - c);
if (r == -1) {
break;
}
c += r;
} while (c < TEST_FILE_LENGTH);
if (r != -1) {
r = message.read();
}
message.close();
} catch (MessageCancelledException e) {
System.out.println("Value of c at message cancelled is " + c);
int i = 0;
while (i < c) {
if (data[i] != received[i]) {
break;
}
i++;
}
wasOk.set(i == c);
} catch (IOException e) {
exRef.set(e);
} finally {
IoUtils.safeClose(message);
latch.countDown();
}
}
}).start();
}
});
MessageOutputStream messageOutputStream = sendChannel.writeMessage();
messageOutputStream.write(data);
messageOutputStream.cancel();
messageOutputStream.close();
// close should be idempotent
messageOutputStream.close();
// no effect expected, since message is closed
messageOutputStream.flush();
latch.await();
IOException exception = exRef.get();
if (exception != null) {
throw exception;
}
assertTrue(wasOk.get());
}
use of com.automatak.dnp3.Channel in project jboss-remoting by jboss-remoting.
the class ChannelTestBase method testRemoteChannelClose.
@Test
public void testRemoteChannelClose() throws Exception {
final CountDownLatch closedLatch = new CountDownLatch(1);
sendChannel.addCloseHandler(new CloseHandler<Channel>() {
public void handleClose(final Channel closed, final IOException exception) {
closedLatch.countDown();
}
});
sendChannel.receiveMessage(new Channel.Receiver() {
public void handleError(final Channel channel, final IOException error) {
channel.closeAsync();
}
public void handleEnd(final Channel channel) {
channel.closeAsync();
}
public void handleMessage(final Channel channel, final MessageInputStream message) {
IoUtils.safeClose(message);
}
});
recvChannel.receiveMessage(new Channel.Receiver() {
public void handleError(final Channel channel, final IOException error) {
channel.closeAsync();
}
public void handleEnd(final Channel channel) {
channel.closeAsync();
}
public void handleMessage(final Channel channel, final MessageInputStream message) {
IoUtils.safeClose(message);
}
});
sendChannel.writeShutdown();
IoUtils.safeClose(recvChannel);
System.out.println("Waiting for closed");
closedLatch.await();
System.out.println("Closed");
}
Aggregations