Search in sources :

Example 46 with Channel

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");
}
Also used : Channel(io.fabric8.openclustermanagement.api.model.multicloudoperatorschannel.apps.v1.Channel) Test(org.junit.jupiter.api.Test)

Example 47 with Channel

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;
        }
    }
}
Also used : MasterStackConfig(com.automatak.dnp3.MasterStackConfig) Master(com.automatak.dnp3.Master) Slf4jChannelListener(net.solarnetwork.dnp3.util.Slf4jChannelListener) InputStreamReader(java.io.InputStreamReader) CommandTaskResult(com.automatak.dnp3.CommandTaskResult) Channel(com.automatak.dnp3.Channel) BufferedReader(java.io.BufferedReader) ControlRelayOutputBlock(com.automatak.dnp3.ControlRelayOutputBlock)

Example 48 with Channel

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;
    }
}
Also used : Channel(com.automatak.dnp3.Channel) DNP3Exception(com.automatak.dnp3.DNP3Exception)

Example 49 with Channel

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());
}
Also used : MessageInputStream(org.jboss.remoting3.MessageInputStream) Channel(org.jboss.remoting3.Channel) MessageCancelledException(org.jboss.remoting3.MessageCancelledException) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MessageOutputStream(org.jboss.remoting3.MessageOutputStream)

Example 50 with Channel

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");
}
Also used : MessageInputStream(org.jboss.remoting3.MessageInputStream) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Channel (org.jboss.remoting3.Channel)41 IOException (java.io.IOException)29 Test (org.junit.Test)14 Connection (org.jboss.remoting3.Connection)12 MessageInputStream (org.jboss.remoting3.MessageInputStream)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 OpenListener (org.jboss.remoting3.OpenListener)10 MessageOutputStream (org.jboss.remoting3.MessageOutputStream)9 InetSocketAddress (java.net.InetSocketAddress)8 URI (java.net.URI)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 IoFuture (org.xnio.IoFuture)7 Channel (com.google.cloud.video.livestream.v1.Channel)6 LivestreamServiceClient (com.google.cloud.video.livestream.v1.LivestreamServiceClient)6 URISyntaxException (java.net.URISyntaxException)6 ManagementClientChannelStrategy (org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy)6 FutureResult (org.xnio.FutureResult)6 ManagementChannelHandler (org.jboss.as.protocol.mgmt.ManagementChannelHandler)5 Endpoint (org.jboss.remoting3.Endpoint)5 ProtocolConnectionConfiguration (org.jboss.as.protocol.ProtocolConnectionConfiguration)4