public static boolean inWildFly() { return options().containsKey("service-registry"); }
@Override public void activate(ServiceActivatorContext serviceActivatorContext) { WunderBoss.registerComponentProvider(Caching.class, new ASCachingProvider()); } }
@Override public void initialize() { this.runtime = new LoaderWrapper(WunderBoss.classLoader()); // we have to touch Clojure.class so it will init clojure enough for // binding the loader's root to work. Without this, we'll NPE Clojure.var("clojure.core", "require"); // we have to bind the loader for cases where the TCCL is the wrong // module inside WildFly (this happens for web requests). If LOADER isn't // bound, clojure.lang.RT will fall back to the TCCL. Compiler.LOADER.bindRoot(WunderBoss.classLoader()); }
public synchronized static void addShutdownAction(Runnable action) { if (!shutdownHook) { if (!inContainer()) { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { try { shutdownAndReset(); } catch (Throwable t) { log.warn("Error in WunderBoss shutdown hook", t); } } })); } shutdownHook = true; } shutdownActions.add(action); }
public static <T extends Component> T findOrCreateComponent(Class<T> clazz) { return findOrCreateComponent(clazz, null, null); }
private static void init() { classLoader = new DynamicClassLoader(WunderBoss.class.getClassLoader()); locator = new ClassPathLocator(classLoader); options = new Options<>(); options.put("root", "."); configureLogback(); }
@Override public boolean enlist() throws Exception { if (TransactionUtil.tm.getTransaction() == null) { return super.isXAEnabled(); } else if (!WunderBoss.inContainer() || isRemote()) { XAResource resource = ((XASession)jmsSession()).getXAResource(); return TransactionUtil.tm.getTransaction().enlistResource(resource); } else { return true; } }
@Override public synchronized boolean schedule(String name, Runnable fn, Map<ScheduleOption, Object> opts) throws Exception { Options<ScheduleOption> options = new Options<>(opts); validateOptions(options); start(); final boolean replacedExisting = unschedule(name); final JobDataMap jobDataMap = new JobDataMap(); final Map contextOptions = new HashMap(); contextOptions.put(ExecutionContext.CreateOption.SINGLETON, options.getBoolean(SINGLETON)); final ImmediateContext context = WunderBoss.findOrCreateComponent(ImmediateContext.class, name, contextOptions); context.setAction(fn); // TODO: Quartz says only serializable things should be in here jobDataMap.put(RunnableJob.RUN_FUNCTION_KEY, context); JobBuilder jobBuilder; if (options.getBoolean(ALLOW_CONCURRENT_EXEC)) { jobBuilder = JobBuilder.newJob(RunnableJob.class); } else { jobBuilder = JobBuilder.newJob(RunnableJob.NotConcurrentlyExecuting.class); } JobDetail job = jobBuilder.usingJobData(jobDataMap).build(); this.scheduler.scheduleJob(job, initTrigger(name, options)); this.currentJobs.put(name, job.getKey()); return replacedExisting; }
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; }
private static <T extends Component> ComponentProvider<T> getComponentProvider(Class<T> iface, boolean throwIfMissing) { ComponentProvider<T> provider = componentProviders.get(iface); if (provider == null && (provider = locator.findComponentProvider(iface)) != null) { registerComponentProvider(iface, provider); } if (throwIfMissing && provider == null) { throw new IllegalArgumentException("Unknown component: " + iface.getName()); } return provider; }
protected void loadProperties() throws Exception { String internalPath = "META-INF/app.properties"; log.debug("Looking for properties file at {}", internalPath); InputStream configStream = WunderBoss.classLoader().getResourceAsStream(internalPath); if (configStream != null) { log.debug("Found properties file {}", internalPath); properties.load(configStream); } Properties externalProperties = new Properties(); String externalPath = jarURL().getPath(); if (externalPath.endsWith(".jar")) { externalPath = externalPath.replace(".jar", ".properties"); log.debug("Looking for properties file at {}", externalPath); File externalFile = new File(externalPath); if (externalFile.exists()) { log.debug("Found properties file {}", externalPath); externalProperties.load(new FileInputStream(externalFile)); properties.putAll(externalProperties); } } }
private EmbeddedCacheManager getWebCacheManager() { ServiceRegistry serviceRegistry = (ServiceRegistry) WunderBoss.options().get("service-registry"); return (EmbeddedCacheManager) serviceRegistry.getRequiredService(WEB_CACHE_MANAGER).getValue(); }
@Override public void activate(ServiceActivatorContext serviceActivatorContext) { WunderBoss.registerComponentProvider(Transaction.class, new ASTransactionProvider()); } }
private TransactionManager getWildFlyTransactionManager() { ServiceRegistry serviceRegistry = (ServiceRegistry) WunderBoss.options().get("service-registry"); return (TransactionManager) serviceRegistry.getRequiredService(TRANSACTION_MANAGER).getValue(); } }
@Override public void activate(ServiceActivatorContext serviceActivatorContext) { WunderBoss.registerComponentProvider(Messaging.class, new ASMessagingProvider()); } }
protected HttpHandler wrapWithStaticHandler(HttpHandler baseHandler, String path) { path = WunderBoss.options().get("root", "").toString() + File.separator + path;
@Override public Messaging create(String name, Options options) { final WunderBossService service = (WunderBossService)WunderBoss.options().get(WunderBossService.KEY); ASDestinationManager destManager; if (ASUtils.containerIsEAP6()) { destManager = new EAPDestinationManager(service.serviceTarget(), ASUtils.messagingServiceName(), service.namingContext()); } else { destManager = new WildFlyDestinationManager(service.serviceTarget(), ASUtils.messagingServiceName()); } return new ASMessaging(name, service, destManager, options); } }