向高速公路注册远程程序 java
Registering remote procedures with autobahn java
在高速公路-java注册手续的标准方式是:
CompletableFuture<Registration> order_to_produce = session.register(prefix + "order_to_produce", this::order_to_produce);
order_to_produce.thenAccept(registration -> LOGGER.info("Registered procedure: " + registration.procedure));
由于我们有很多函数要注册,所以我想将注册名称和函数放到 HashMap 中,但我无法通过方法引用来引用任何函数。
我想做这样的东西:
Map<String, Runnable> functions = new HashMap<>();
functions.put("order_to_produce", this::order_to_produce);
for (Map.Entry<String, Runnable> function : functions.entrySet())
{
CompletableFuture<Registration> registerProcedure = session.register(prefix + function.getKey(), function.getValue());
registerProcedure.thenAccept(registration -> LOGGER.info("Registered procedure: " + registration.procedure));
// or using reflection ?
//
CompletableFuture<Registration> registerProcedure = session.register(prefix + function.getKey(), obj.getClass().getMethod(function.getKey()));
registerProcedure.thenAccept(registration -> LOGGER.info("Registered procedure: " + registration.procedure));
}
有办法吗?
在 python 中,我可以在后端组件上轻松做到这一点。
functions = {'backend.add_service': self.add_service,
'backend.online_services': self.services_online}
for functionToRegister in functions.keys():
yield self.register(functions[functionToRegister], functionToRegister, options=self.REGISTER_OPTIONS)
问候,Marko。
我仍然对原始问题感兴趣,但现在我是这样的:
LinkedList<CompletableFuture<Registration>> functions = new LinkedList<>();
functions.add(session.register(prefix + "order_to_produce", this::order_to_produce));
for (CompletableFuture<Registration> function : functions) {
function.thenAccept(registration -> LOGGER.info("Registered procedure: " + registration.procedure));
}
在高速公路-java注册手续的标准方式是:
CompletableFuture<Registration> order_to_produce = session.register(prefix + "order_to_produce", this::order_to_produce);
order_to_produce.thenAccept(registration -> LOGGER.info("Registered procedure: " + registration.procedure));
由于我们有很多函数要注册,所以我想将注册名称和函数放到 HashMap 中,但我无法通过方法引用来引用任何函数。
我想做这样的东西:
Map<String, Runnable> functions = new HashMap<>();
functions.put("order_to_produce", this::order_to_produce);
for (Map.Entry<String, Runnable> function : functions.entrySet())
{
CompletableFuture<Registration> registerProcedure = session.register(prefix + function.getKey(), function.getValue());
registerProcedure.thenAccept(registration -> LOGGER.info("Registered procedure: " + registration.procedure));
// or using reflection ?
//
CompletableFuture<Registration> registerProcedure = session.register(prefix + function.getKey(), obj.getClass().getMethod(function.getKey()));
registerProcedure.thenAccept(registration -> LOGGER.info("Registered procedure: " + registration.procedure));
}
有办法吗?
在 python 中,我可以在后端组件上轻松做到这一点。
functions = {'backend.add_service': self.add_service,
'backend.online_services': self.services_online}
for functionToRegister in functions.keys():
yield self.register(functions[functionToRegister], functionToRegister, options=self.REGISTER_OPTIONS)
问候,Marko。
我仍然对原始问题感兴趣,但现在我是这样的:
LinkedList<CompletableFuture<Registration>> functions = new LinkedList<>();
functions.add(session.register(prefix + "order_to_produce", this::order_to_produce));
for (CompletableFuture<Registration> function : functions) {
function.thenAccept(registration -> LOGGER.info("Registered procedure: " + registration.procedure));
}