public String getString(T key) { return getString(key, null); }
@Override public Object call() throws Exception { Connection connection; if (options.has(CreateContextOption.USERNAME)) { connection = cf.createConnection(options.getString(CreateContextOption.USERNAME), options.getString(CreateContextOption.PASSWORD)); } else { connection = cf.createConnection(); } return connection; } });
public static synchronized ExecutorService workerPool() { if (workerExecutor == null) { final String deploymentName = options().getString("deployment-name", "wunderboss"); workerExecutor = Executors.newCachedThreadPool(new ThreadFactory() { private final AtomicLong counter = new AtomicLong(0); @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("%s-worker-%d", deploymentName, counter.getAndIncrement())); } }); } return workerExecutor; }
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 MessageConsumer createConsumer(final Destination destination, final Context context, final Options<Destination.ListenOption> options) throws JMSException { return ((JMSSpecificContext)context) .jmsSession() .createConsumer(((JMSDestination) destination).jmsDestination(), options.getString(Destination.ListenOption.SELECTOR)); } }
void mode() { String m = options.getString(Caching.CreateOption.MODE); if (m != null) { builder.clustering().cacheMode(CacheMode.valueOf(m.toUpperCase())); } } void evict() {
@Override public boolean unregister(Map<RegisterOption, Object> opts) { final Options<RegisterOption> options = new Options<>(opts); return pathology.remove(options.getString(RegisterOption.PATH), options.getList(RegisterOption.VHOSTS)); }
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; }
void evict() { builder.eviction() .strategy(EvictionStrategy.valueOf(options.getString(Caching.CreateOption.EVICTION).toUpperCase())) .maxEntries(options.getInt(Caching.CreateOption.MAX_ENTRIES)); } void expire() {
protected ConnectionFactory createRemoteConnectionFactory(final Options<CreateContextOption> options) { //TODO: possibly cache the remote cf's? Map<String, Object> transportOpts = new HashMap<>(); transportOpts.put("host", options.getString(CreateContextOption.HOST)); transportOpts.put("port", options.getInt(CreateContextOption.PORT)); if (REMOTE_TYPE_WILDFLY.equals(options.getString(CreateContextOption.REMOTE_TYPE))) { transportOpts.put("http-upgrade-enabled", true); } TransportConfiguration config = new TransportConfiguration("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", transportOpts); HornetQConnectionFactory hornetQcf = HornetQJMSClient .createConnectionFactoryWithoutHA(options.has(CreateContextOption.XA) ? JMSFactoryType.XA_CF : JMSFactoryType.CF, config); hornetQcf.setReconnectAttempts(options.getInt(CreateContextOption.RECONNECT_ATTEMPTS)); hornetQcf.setRetryInterval(options.getLong(CreateContextOption.RECONNECT_RETRY_INTERVAL)); hornetQcf.setRetryIntervalMultiplier(options.getDouble(CreateContextOption.RECONNECT_RETRY_INTERVAL_MULTIPLIER)); hornetQcf.setMaxRetryInterval(options.getLong(CreateContextOption.RECONNECT_MAX_RETRY_INTERVAL)); // We have to cast for HornetQ 2.3 - the factory object that is returned is both a HornetQConnectionFactory // and a javax.jms.ConnectionFactory, but HornetQConnectionFactory doesn't implement j.j.ConnectionFactory. // With HornetQ 2.4, this cast is redundant. return (ConnectionFactory)hornetQcf; }
@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); }
protected boolean registerHandler(HttpHandler httpHandler, Map<RegisterOption, Object> opts, Runnable cleanup) { final Options<RegisterOption> options = new Options<>(opts); final String context = options.getString(RegisterOption.PATH); httpHandler = wrapWithSessionHandler(httpHandler); if (options.has(RegisterOption.STATIC_DIR)) { httpHandler = wrapWithStaticHandler(httpHandler, options.getString(RegisterOption.STATIC_DIR)); } if (options.getBoolean(RegisterOption.DISPATCH)) { httpHandler = wrapWithDispatcher(httpHandler); } final boolean replacement = pathology.add(context, options.getList(RegisterOption.VHOSTS), httpHandler); if (cleanup != null) { pathology.epilogue(httpHandler, cleanup); } if (autoStart) { start(); } log.info("Registered web context {}", context); return replacement; }
protected Trigger initTrigger(String name, Options<ScheduleOption> opts) { TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger() .withIdentity(name, name()); if (opts.has(AT)) { builder.startAt(opts.getDate(AT)); } else if (opts.has(IN)) { builder.startAt(new java.util.Date(System.currentTimeMillis() + opts.getLong(IN))); } else { builder.startNow(); } if (opts.has(UNTIL)) { builder.endAt(opts.getDate(UNTIL)); } if (opts.has(CRON)) { builder.withSchedule(CronScheduleBuilder.cronSchedule(opts.getString(CRON))); } else if (opts.has(EVERY)) { SimpleScheduleBuilder schedule = SimpleScheduleBuilder.simpleSchedule() .withIntervalInMilliseconds(opts.getInt(EVERY)); if (opts.has(LIMIT)) { schedule.withRepeatCount(opts.getInt(LIMIT) - 1); } else { schedule.repeatForever(); } builder.withSchedule(schedule); } return builder.build(); }
} else { queue = createQueue(name, opts.getString(CreateQueueOption.SELECTOR, ""), opts.getBoolean(CreateQueueOption.DURABLE)); addCreatedDestination(DestinationUtil.fullName(name, JMSDestination.Type.QUEUE));
Session jmsSession = context.jmsSession(); javax.jms.Destination destination = jmsDestination(); String selector = opts.getString(ReceiveOption.SELECTOR); MessageConsumer consumer = jmsSession.createConsumer(destination, selector);
void transact() { if (options.getBoolean(Caching.CreateOption.TRANSACTIONAL)) { LockingMode mode = LockingMode.valueOf(options.getString(Caching.CreateOption.LOCKING).toUpperCase()); builder.transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .transactionManagerLookup(TM_LOOKUP) .lockingMode(mode) .recovery() .versioning().enabled(mode==LockingMode.OPTIMISTIC).scheme(VersioningScheme.SIMPLE) .locking() .isolationLevel(mode==LockingMode.OPTIMISTIC ? IsolationLevel.REPEATABLE_READ : IsolationLevel.READ_COMMITTED) .writeSkewCheck(mode==LockingMode.OPTIMISTIC); } else { builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); } }
@Override public Context createContext(Map<CreateContextOption, Object> options) throws Exception { final Options<CreateContextOption> opts = new Options<>(options); JMSSpecificContext context; boolean xa = opts.getBoolean(CreateContextOption.XA); ConnectionFactory cf; if (opts.has(CreateContextOption.HOST)) { cf = createRemoteConnectionFactory(opts); } else { start(); cf = (ConnectionFactory)lookupJNDI(xa ? JNDI_XA_CF_NAME : JNDI_CF_NAME); } if (xa) { context = createXAContext((XAConnectionFactory)cf, opts); } else { context = createContext(cf, opts); } if (opts.has(CreateContextOption.CLIENT_ID)) { context.jmsConnection().setClientID(opts.getString(CreateContextOption.CLIENT_ID)); } return context; }
private void configure(Options<CreateOption> options) { autoStart = options.getBoolean(CreateOption.AUTO_START); Undertow.Builder builder = (Undertow.Builder) options.get(CreateOption.CONFIGURATION); if (builder != null) { undertow = builder .setHandler(Handlers.header(pathology.handler(), Headers.SERVER_STRING, "undertow")) .build(); } else { int port = options.getInt(CreateOption.PORT); String host = options.getString(CreateOption.HOST); undertow = Undertow.builder() .addHttpListener(port, host) .setHandler(Handlers.header(pathology.handler(), Headers.SERVER_STRING, "undertow")) .build(); } }
@Override public Listener subscribe(final String id, final MessageHandler handler, final Codecs codecs, final Map<SubscribeOption, Object> options) throws Exception { Options<SubscribeOption> opts = new Options<>(options); final JMSSpecificContext context = (JMSSpecificContext)context(id, opts.get(SubscribeOption.CONTEXT)); final TopicSubscriber subscriber = context .jmsSession() .createDurableSubscriber((javax.jms.Topic) jmsDestination(), id, opts.getString(SubscribeOption.SELECTOR), false); final Listener listener = new JMSListener(handler, codecs, this, context, subscriber).start(); Context parent = (Context)opts.get(SubscribeOption.CONTEXT); if (parent != null) { parent.addCloseable(listener); } broker().addCloseableForDestination(this, listener); return new Listener() { @Override public void close() throws Exception { listener.close(); context.close(); } }; }