public static synchronized void putOption(String k, Object v) { options.put(k, v); }
protected Options<CreateOption> validate(Map<CreateOption,Object> options) { Options<CreateOption> result = new Options<CreateOption>(options); String mode = result.getString(CreateOption.MODE); if (mode != null && !"LOCAL".equalsIgnoreCase(mode)) { log.warn("Requested mode only available in a cluster, setting to LOCAL"); result.put(CreateOption.MODE, "LOCAL"); } return result; }
protected Options<MessageOpOption> replyOptions(Map<Destination.MessageOpOption, Object> options) throws Exception { Options<MessageOpOption> opts = new Options<>(options); Map<String, Object> properties = (Map<String, Object>)opts.get(Destination.PublishOption.PROPERTIES); Map<String, Object> newProperties = new HashMap<>(); if (properties != null) { newProperties.putAll(properties); } newProperties.put(SYNC_RESPONSE_PROPERTY, true); newProperties.put(REQUEST_ID_PROPERTY, requestID()); newProperties.put(REQUEST_NODE_ID_PROPERTY, requestNodeID()); opts.put(Destination.PublishOption.PROPERTIES, newProperties); return opts; }
@Override public Reply onMessage(Message msg, Context context) throws Exception { Reply result = handler.onMessage(msg, context); Options<MessageOpOption> replyOptions = new Options<>(); replyOptions.put(PublishOption.TTL, opts.getInt(RespondOption.TTL)); replyOptions.put(PublishOption.CONTEXT, context); replyOptions.put(PublishOption.PROPERTIES, result.properties()); ((ReplyableMessage)msg).reply(result.content(), codecs.forContentType(msg.contentType()), replyOptions); return null; } };
protected Options<CreateOption> validate(Map<CreateOption,Object> options) { Options<CreateOption> result = new Options<CreateOption>(options); String mode = result.getString(CreateOption.MODE); // Default mode when in a cluster if (mode == null && ASUtils.inCluster()) { result.put(CreateOption.MODE, "DIST_SYNC"); } return result; }
private static void init() { classLoader = new DynamicClassLoader(WunderBoss.class.getClassLoader()); locator = new ClassPathLocator(classLoader); options = new Options<>(); options.put("root", "."); configureLogback(); }
@Override public Response request(Object content, Codec codec, Codecs codecs, Map<MessageOpOption, Object> options) throws Exception { final Options<MessageOpOption> opts = new Options<>(options); final String id = UUID.randomUUID().toString(); final JMSSpecificContext context = (JMSSpecificContext)opts.get(MessageOpOption.CONTEXT); final String nodeId = context != null ? context.id() : JMSMessagingSkeleton.BROKER_ID; final ConcreteResponse response = new ConcreteResponse(); Options<ListenOption> routerOpts = new Options<>(); routerOpts.put(ListenOption.CONCURRENCY, 1); routerOpts.put(ListenOption.SELECTOR, JMSMessage.REQUEST_NODE_ID_PROPERTY + " = '" + nodeId + "' AND " + JMSMessage.SYNC_RESPONSE_PROPERTY + " = TRUE"); if (context != null && context.isRemote()) { routerOpts.put(ListenOption.CONTEXT, context); } ResponseRouter.routerFor(this, codecs, routerOpts).registerResponse(id, response); publish(content, codec, options, new HashMap<String, Object>() {{ put(JMSMessage.REQUEST_NODE_ID_PROPERTY, nodeId); put(JMSMessage.SYNC_PROPERTY, true); put(JMSMessage.REQUEST_ID_PROPERTY, id); }}); return response; }
@Override public Listener respond(final MessageHandler handler, final Codecs codecs, Map<ListenOption, Object> options) throws Exception { final Options<ListenOption> opts = new Options<>(options); String selector = JMSMessage.SYNC_PROPERTY + " = TRUE"; if (opts.has(ListenOption.SELECTOR)) { selector += " AND " + opts.getString(ListenOption.SELECTOR); } opts.put(ListenOption.SELECTOR, selector); MessageHandler wrappedHandler = new MessageHandler() { @Override public Reply onMessage(Message msg, Context context) throws Exception { Reply result = handler.onMessage(msg, context); Options<MessageOpOption> replyOptions = new Options<>(); replyOptions.put(PublishOption.TTL, opts.getInt(RespondOption.TTL)); replyOptions.put(PublishOption.CONTEXT, context); replyOptions.put(PublishOption.PROPERTIES, result.properties()); ((ReplyableMessage)msg).reply(result.content(), codecs.forContentType(msg.contentType()), replyOptions); return null; } }; return listen(wrappedHandler, codecs, opts); }