• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java FactoryManager类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.apache.sshd.common.FactoryManager的典型用法代码示例。如果您正苦于以下问题:Java FactoryManager类的具体用法?Java FactoryManager怎么用?Java FactoryManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

FactoryManager类属于org.apache.sshd.common包,在下文中一共展示了FactoryManager类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: startClient

点赞 3

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
private void startClient() throws IOException {
    client = SshClient.setUpDefaultClient();
    client.getProperties().putIfAbsent(FactoryManager.IDLE_TIMEOUT,
            TimeUnit.SECONDS.toMillis(idleTimeout));
    client.getProperties().putIfAbsent(FactoryManager.NIO2_READ_TIMEOUT,
            TimeUnit.SECONDS.toMillis(idleTimeout + 15L));
    client.start();
    client.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    startSession();
}
 

开发者ID:opennetworkinglab,
项目名称:onos,
代码行数:11,
代码来源:NetconfSessionMinaImpl.java

示例2: startServer

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
public void startServer(Integer timeout) throws Exception {
  if (server != null) {
    throw failure("Server already started");
  }
  server = SshServer.setUpDefaultServer();
  if (timeout != null) {
    server.setProperties(Collections.singletonMap(FactoryManager.AUTH_TIMEOUT, timeout.toString()));
  }
  server.setPort(5000);
  server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
  server.setPasswordAuthenticator((username, password, sess) -> authenticator.authenticate(username, password, sess));
  server.setShellFactory(new EchoShellFactory());
  server.setServiceFactories(Arrays.asList(ServerConnectionServiceFactory.INSTANCE, AsyncUserAuthServiceFactory.INSTANCE));
  server.start();
}
 

开发者ID:aeshell,
项目名称:aesh-readline,
代码行数:16,
代码来源:AsyncAuthTestBase.java

示例3: setUp

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    sshd = setupTestServer();
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, TIMEOUT);
    sshd.setShellFactory(new TestEchoShellFactory());
    sshd.start();
    port = sshd.getPort();
}
 

开发者ID:termd,
项目名称:termd,
代码行数:9,
代码来源:KeepAliveTest.java

示例4: setUp

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
protected void setUp(long bytesLimit, long timeLimit, long packetsLimit) throws Exception {
    sshd = setupTestServer();
    if (bytesLimit > 0L) {
        PropertyResolverUtils.updateProperty(sshd, FactoryManager.REKEY_BYTES_LIMIT, bytesLimit);
    }
    if (timeLimit > 0L) {
        PropertyResolverUtils.updateProperty(sshd, FactoryManager.REKEY_TIME_LIMIT, timeLimit);
    }
    if (packetsLimit > 0L) {
        PropertyResolverUtils.updateProperty(sshd, FactoryManager.REKEY_PACKETS_LIMIT, packetsLimit);
    }

    sshd.start();
    port = sshd.getPort();
}
 

开发者ID:termd,
项目名称:termd,
代码行数:16,
代码来源:KeyReExchangeTest.java

示例5: testAuthenticationTimeout

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Test
public void testAuthenticationTimeout() throws Exception {
    final long testAuthTimeout = TimeUnit.SECONDS.toMillis(5L);
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.AUTH_TIMEOUT, testAuthTimeout);

    sshd.start();
    client.start();
    try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) {
        Collection<ClientSession.ClientSessionEvent> res = s.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED), 2L * testAuthTimeout);
        assertTrue("Session should be closed: " + res,
                   res.containsAll(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.WAIT_AUTH)));
    } finally {
        client.stop();
    }
}
 

开发者ID:termd,
项目名称:termd,
代码行数:16,
代码来源:ServerTest.java

示例6: createNativeSession

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
protected ClientSession createNativeSession() throws Exception {
    client = setupTestClient();
    PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048);
    PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256);
    client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
    client.start();

    ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshPort).verify(7L, TimeUnit.SECONDS).getSession();
    session.addPasswordIdentity(getCurrentTestName());
    session.auth().verify(11L, TimeUnit.SECONDS);
    return session;
}
 

开发者ID:termd,
项目名称:termd,
代码行数:13,
代码来源:PortForwardingTest.java

示例7: startServer

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
public void startServer(Integer timeout) throws Exception {
  if (server != null) {
    throw failure("Server already started");
  }
  server = SshServer.setUpDefaultServer();
  if (timeout != null) {
    server.getProperties().put(FactoryManager.AUTH_TIMEOUT, timeout.toString());
  }
  server.setPort(5000);
  server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
  server.setPasswordAuthenticator((username, password, sess) -> authenticator.authenticate(username, password, sess));
  server.setShellFactory(new EchoShellFactory());
  server.setServiceFactories(Arrays.asList(ServerConnectionServiceFactory.INSTANCE, AsyncUserAuthServiceFactory.INSTANCE));
  server.start();
}
 

开发者ID:termd,
项目名称:termd,
代码行数:16,
代码来源:AsyncAuthTestBase.java

示例8: create

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Override
public IoServiceFactory create(FactoryManager manager) {
  return new NettyIoServiceFactory(eventLoopGroup, handlerBridge);
}
 

开发者ID:aeshell,
项目名称:aesh-readline,
代码行数:5,
代码来源:NettyIoServiceFactoryFactory.java

示例9: create

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Override
public IoServiceFactory create(FactoryManager manager) {
  return new TestServiceFactory(manager, getExecutorService(), isShutdownOnExit());
}
 

开发者ID:aeshell,
项目名称:aesh-readline,
代码行数:5,
代码来源:TestIoServiceFactoryFactory.java

示例10: TestServiceFactory

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
public TestServiceFactory(FactoryManager factoryManager, ExecutorService service, boolean shutdownOnExit) {
  super(factoryManager, service, shutdownOnExit);
}
 

开发者ID:aeshell,
项目名称:aesh-readline,
代码行数:4,
代码来源:TestServiceFactory.java

示例11: testWindowConsumptionWithInvertedStreams

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Test
public void testWindowConsumptionWithInvertedStreams() throws Exception {
    sshd.setShellFactory(new AsyncEchoShellFactory());
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024);
    PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024);
    client.start();

    try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
        session.addPasswordIdentity(getCurrentTestName());
        session.auth().verify(5L, TimeUnit.SECONDS);

        try (ChannelShell channel = session.createShellChannel()) {
            channel.open().verify(5L, TimeUnit.SECONDS);

            try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) {
                Window clientLocal = channel.getLocalWindow();
                Window clientRemote = channel.getRemoteWindow();
                Window serverLocal = serverChannel.getLocalWindow();
                Window serverRemote = serverChannel.getRemoteWindow();

                final String message = "0123456789";
                final int nbMessages = 500;

                try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(channel.getInvertedIn()));
                     BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInvertedOut()))) {

                    for (int i = 0; i < nbMessages; i++) {
                        writer.write(message);
                        writer.write("\n");
                        writer.flush();

                        waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));

                        String line = reader.readLine();
                        assertEquals("Mismatched message at line #" + i, message, line);

                        waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));
                        waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L));
                    }
                }
            }
        }
    } finally {
        client.stop();
    }
}
 

开发者ID:termd,
项目名称:termd,
代码行数:47,
代码来源:WindowTest.java

示例12: testWindowConsumptionWithDirectStreams

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Test
public void testWindowConsumptionWithDirectStreams() throws Exception {
    sshd.setShellFactory(new AsyncEchoShellFactory());
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024);
    PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024);

    client.start();

    try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
        session.addPasswordIdentity(getCurrentTestName());
        session.auth().verify(5L, TimeUnit.SECONDS);

        try (ChannelShell channel = session.createShellChannel();
             PipedInputStream inPis = new PipedInputStream();
             PipedOutputStream inPos = new PipedOutputStream(inPis);
             PipedInputStream outPis = new PipedInputStream();
             PipedOutputStream outPos = new PipedOutputStream(outPis)) {

            channel.setIn(inPis);
            channel.setOut(outPos);
            channel.open().verify(7L, TimeUnit.SECONDS);

            try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) {
                Window clientLocal = channel.getLocalWindow();
                Window clientRemote = channel.getRemoteWindow();
                Window serverLocal = serverChannel.getLocalWindow();
                Window serverRemote = serverChannel.getRemoteWindow();

                final String message = "0123456789";
                final int nbMessages = 500;

                try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(inPos));
                     BufferedReader reader = new BufferedReader(new InputStreamReader(outPis))) {
                    for (int i = 0; i < nbMessages; i++) {
                        writer.write(message);
                        writer.write('\n');
                        writer.flush();

                        waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));

                        String line = reader.readLine();
                        assertEquals("Mismatched message at line #" + i, message, line);

                        waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));
                        waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L));
                    }
                }
            }
        }
    } finally {
        client.stop();
    }
}
 

开发者ID:termd,
项目名称:termd,
代码行数:54,
代码来源:WindowTest.java

示例13: testWindowConsumptionWithAsyncStreams

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Test
public void testWindowConsumptionWithAsyncStreams() throws Exception {
    sshd.setShellFactory(new AsyncEchoShellFactory());
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024);
    PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024);

    client.start();

    try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
        session.addPasswordIdentity(getCurrentTestName());
        session.auth().verify(5L, TimeUnit.SECONDS);

        try (ChannelShell channel = session.createShellChannel()) {
            channel.setStreaming(ClientChannel.Streaming.Async);
            channel.open().verify(5L, TimeUnit.SECONDS);

            try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) {
                Window clientLocal = channel.getLocalWindow();
                Window clientRemote = channel.getRemoteWindow();
                Window serverLocal = serverChannel.getLocalWindow();
                Window serverRemote = serverChannel.getRemoteWindow();

                final String message = "0123456789\n";
                final byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
                final int nbMessages = 500;
                IoOutputStream output = channel.getAsyncIn();
                IoInputStream input = channel.getAsyncOut();
                for (int i = 0; i < nbMessages; i++) {
                    Buffer buffer = new ByteArrayBuffer(bytes);
                    output.write(buffer).verify(5L, TimeUnit.SECONDS);

                    waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));

                    Buffer buf = new ByteArrayBuffer(16);
                    IoReadFuture future = input.read(buf);
                    future.verify(5L, TimeUnit.SECONDS);
                    assertEquals("Mismatched available data at line #" + i, message.length(), buf.available());
                    assertEquals("Mismatched data at line #" + i, message, new String(buf.array(), buf.rpos(), buf.available()));

                    waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));
                    waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L));
                }
            }
        }
    } finally {
        client.stop();
    }
}
 

开发者ID:termd,
项目名称:termd,
代码行数:49,
代码来源:WindowTest.java

示例14: setUp

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    sshd = setupTestServer();
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048);
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256);
    sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
    sshd.start();

    if (!requestsQ.isEmpty()) {
        requestsQ.clear();
    }

    final TcpipForwarderFactory factory = ValidateUtils.checkNotNull(sshd.getTcpipForwarderFactory(), "No TcpipForwarderFactory");
    sshd.setTcpipForwarderFactory(new TcpipForwarderFactory() {
        private final Class<?>[] interfaces = {TcpipForwarder.class};
        private final Map<String, String> method2req = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) {
            private static final long serialVersionUID = 1L;    // we're not serializing it...

            {
                put("localPortForwardingRequested", TcpipForwardHandler.REQUEST);
                put("localPortForwardingCancelled", CancelTcpipForwardHandler.REQUEST);
            }
        };

        @Override
        public TcpipForwarder create(ConnectionService service) {
            Thread thread = Thread.currentThread();
            ClassLoader cl = thread.getContextClassLoader();

            final TcpipForwarder forwarder = factory.create(service);
            return (TcpipForwarder) Proxy.newProxyInstance(cl, interfaces, new InvocationHandler() {
                @SuppressWarnings("synthetic-access")
                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    Object result = method.invoke(forwarder, args);
                    String name = method.getName();
                    String request = method2req.get(name);
                    if (GenericUtils.length(request) > 0) {
                        if (requestsQ.offer(request)) {
                            log.info("Signal " + request);
                        } else {
                            log.error("Failed to offer request=" + request);
                        }
                    }
                    return result;
                }
            });
        }
    });
    sshPort = sshd.getPort();

    NioSocketAcceptor acceptor = new NioSocketAcceptor();
    acceptor.setHandler(new IoHandlerAdapter() {
        @Override
        public void messageReceived(IoSession session, Object message) throws Exception {
            IoBuffer recv = (IoBuffer) message;
            IoBuffer sent = IoBuffer.allocate(recv.remaining());
            sent.put(recv);
            sent.flip();
            session.write(sent);
        }
    });
    acceptor.setReuseAddress(true);
    acceptor.bind(new InetSocketAddress(0));
    echoPort = acceptor.getLocalAddress().getPort();
    this.acceptor = acceptor;
}
 

开发者ID:termd,
项目名称:termd,
代码行数:68,
代码来源:PortForwardingTest.java

示例15: runClient

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@SuppressWarnings("checkstyle:nestedtrydepth")
protected void runClient(String msg) throws Exception {
    try (SshClient client = setupTestClient()) {
        PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 1024 * 16);
        PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024 * 8);
        client.setKeyExchangeFactories(Arrays.asList(
                ClientBuilder.DH2KEX.transform(BuiltinDHFactories.dhg1)));
        client.setCipherFactories(Arrays.<NamedFactory<Cipher>>asList(BuiltinCiphers.blowfishcbc));
        client.start();
        try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
            session.addPasswordIdentity(getCurrentTestName());
            session.auth().verify(5L, TimeUnit.SECONDS);

            try (ByteArrayOutputStream out = new ByteArrayOutputStream();
                 ByteArrayOutputStream err = new ByteArrayOutputStream();
                 ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) {
                channel.setOut(out);
                channel.setErr(err);

                try {
                    channel.open().verify(9L, TimeUnit.SECONDS);
                    try (OutputStream pipedIn = channel.getInvertedIn()) {
                        msg += "\nexit\n";
                        pipedIn.write(msg.getBytes(StandardCharsets.UTF_8));
                        pipedIn.flush();
                    }

                    Collection<ClientChannelEvent> result =
                            channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), TimeUnit.SECONDS.toMillis(15L));
                    assertFalse("Timeout while waiting for channel closure", result.contains(ClientChannelEvent.TIMEOUT));
                } finally {
                    channel.close(false);
                }

                assertArrayEquals("Mismatched message data", msg.getBytes(StandardCharsets.UTF_8), out.toByteArray());
            }
        } finally {
            client.stop();
        }
    }
}
 

开发者ID:termd,
项目名称:termd,
代码行数:42,
代码来源:LoadTest.java

示例16: SharedExecutorMinaConnector

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
public SharedExecutorMinaConnector(Executor executor, IoProcessor<NioSession> ioProcessor, FactoryManager manager, IoHandler handler) {
    super(manager, handler);
    this.executor = executor;
    this.ioProcessor = ioProcessor;
}
 

开发者ID:cloudnautique,
项目名称:cloud-cattle,
代码行数:6,
代码来源:SharedExecutorMinaConnector.java

示例17: SharedExecutorMinaAcceptor

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
public SharedExecutorMinaAcceptor(Executor executor, IoProcessor<NioSession> ioProcessor, FactoryManager manager, IoHandler handler) {
    super(manager, handler);
    this.executor = executor;
    this.ioProcessor = ioProcessor;
}
 

开发者ID:cloudnautique,
项目名称:cloud-cattle,
代码行数:6,
代码来源:SharedExecutorMinaAcceptor.java

示例18: createConnector

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Override
public IoConnector createConnector(FactoryManager manager, IoHandler handler) {
    return new SharedExecutorMinaConnector(executor, ioProcessor, manager, handler);
}
 

开发者ID:cloudnautique,
项目名称:cloud-cattle,
代码行数:5,
代码来源:SharedExecutorMinaServiceServiceFactory.java

示例19: createAcceptor

点赞 2

import org.apache.sshd.common.FactoryManager; //导入依赖的package包/类
@Override
public IoAcceptor createAcceptor(FactoryManager manager, IoHandler handler) {
    return new SharedExecutorMinaAcceptor(executor, ioProcessor, manager, handler);
}
 

开发者ID:cloudnautique,
项目名称:cloud-cattle,
代码行数:5,
代码来源:SharedExecutorMinaServiceServiceFactory.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)