本文整理汇总了Java中net.i2cat.netconf.rpc.RPCElement类的典型用法代码示例。如果您正苦于以下问题:Java RPCElement类的具体用法?Java RPCElement怎么用?Java RPCElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RPCElement类属于net.i2cat.netconf.rpc包,在下文中一共展示了RPCElement类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
Server server = Server.createServerStoringMessages(2222);
server.startServer();
// read lines form input
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
while (true) {
if (buffer.readLine().equalsIgnoreCase("EXIT")) {
break;
}
log.info("Messages received(" + server.getStoredMessages().size() + "):");
for (RPCElement rpcElement : server.getStoredMessages()) {
log.info("##### BEGIN message #####\n" +
rpcElement.toXML() + '\n' +
"##### END message #####");
}
}
log.info("Exiting");
System.exit(0);
}
示例2: createServerStoringMessages
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
/**
* Creates a server listening in loopback interface and store all received messages
*
* @param listeningPort
* where the server will listen for SSH connections
*
*/
public static Server createServerStoringMessages(int listeningPort) {
Server server = new Server();
server.messages = new ArrayList<RPCElement>();
server.storeMessages = true;
server.initializeServer("localhost", listeningPort);
return server;
}
示例3: storeMessage
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
@Override
public void storeMessage(RPCElement message) {
if (messages != null) {
synchronized (messages) {
log.info("Storing message");
messages.add(message);
}
}
}
示例4: getStoredMessages
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
@Override
public List<RPCElement> getStoredMessages() {
if (storeMessages) {
synchronized (messages) {
return Collections.unmodifiableList(messages);
}
} else {
throw new ServerException(new UnsupportedOperationException("Server is configured to not store messages!"));
}
}
示例5: asyncSend
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
@Override
public void asyncSend(Object requestMessage) throws ProtocolException {
// Send a message to the device, and don't wait for the response
RPCElement rpcReply = null;
try {
Query rpcQuery = (Query) requestMessage;
netconfSession.sendAsyncQuery(rpcQuery);
} catch (Exception ex) {
throw new ProtocolException(ex);
}
}
示例6: sendReceive
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
@Override
public Object sendReceive(Object requestMessage) throws ProtocolException {
// Send a message to the device, and wait for the response
RPCElement rpcReply = null;
try {
Query rpcQuery = (Query) requestMessage;
rpcReply = netconfSession.sendSyncQuery(rpcQuery);
} catch (Exception ex) {
throw new ProtocolException(ex);
}
return rpcReply;
}
示例7: receiveRPCElement
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
@Override
public void receiveRPCElement(RPCElement element) {
log.info("Message received");
}
示例8: storeMessage
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
/**
* Store a Netconf message
*
* @param message
* any Netconf message to store
*/
public void storeMessage(RPCElement message);
示例9: getStoredMessages
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
/**
* Get the full list of stored messages
*
* @return a {@link List} of stored messages
*/
public List<RPCElement> getStoredMessages();
示例10: testMessageStoring
import net.i2cat.netconf.rpc.RPCElement; //导入依赖的package包/类
@Test
public void testMessageStoring() {
Server server = Server.createServerStoringMessages(2222);
server.startServer();
try {
SessionContext sessionContext = new SessionContext();
sessionContext.setURI(new URI("ssh://user:[email protected]:2222/"));
INetconfSession session = new NetconfSession(sessionContext);
session.connect();
// send 3 messages
Query query = QueryFactory.newGetConfig("running", null, null);
session.sendSyncQuery(query);
query = QueryFactory.newDeleteConfig("running");
session.sendSyncQuery(query);
query = QueryFactory.newCopyConfig("running", null);
session.sendSyncQuery(query);
// check stored messages
List<RPCElement> messages = server.getStoredMessages();
Assert.assertEquals("Message list must contain 4 messages", (3 + 1), messages.size());
Assert.assertTrue("First message must be a Hello", messages.get(0) instanceof Hello);
Assert.assertTrue("Second message must be a Query with GET-CONFIG operation",
messages.get(1) instanceof Query && ((Query) messages.get(1)).getOperation().equals(Operation.GET_CONFIG));
Assert.assertTrue("Third message must be a Query with DELETE-CONFIG operation",
messages.get(2) instanceof Query && ((Query) messages.get(2)).getOperation().equals(Operation.DELETE_CONFIG));
Assert.assertTrue("Fourth message must be a Query with COPY-CONFIG operation",
messages.get(3) instanceof Query && ((Query) messages.get(3)).getOperation().equals(Operation.COPY_CONFIG));
} catch (Exception e) {
Assert.fail("Error creating session: " + e.getMessage());
} finally {
server.stopServer();
}
}