public static DependencyInjector init(Environment environment, Module... modules) throws DependencyInjectorException { if (isInit) { throw new DependencyInjectorException("DependencyInjector has already been initialized."); } instance = new DependencyInjector(environment, modules); return instance; }
@Override public <T> Future<T> submitCallable(final Callable<T> callable, final Map<Object, Object> threadBindings) { return submitCallable(callable, new IgnoredCallableResult<>(), threadBindings); }
private Integer getLatestDeployedBotVersion(String botId) throws ServiceException { return botFactory.getLatestBot(unrestricted, botId).getBotVersion(); }
@Override public <T> Future<T> submitCallable(final Callable<T> callable, final IFinishedExecution<T> callback, final Map<Object, Object> threadBindings) { return getExecutorService().submit(() -> { try { if (threadBindings != null) { ThreadContext.setResources(threadBindings); } final T result = callable.call(); callback.onComplete(result); return result; } catch (Throwable t) { log.error(t.getLocalizedMessage(), t); callback.onFailure(t); return null; } finally { ThreadContext.remove(); } }); }
public PermissionResponseInterceptor() { injector = DependencyInjector.getInstance(); this.userStore = injector.getInstance(IUserStore.class); this.permissionStore = injector.getInstance(IPermissionStore.class); }
public void init() { if (!isInit) { initLogging(); if (projectName == null || projectName.isEmpty()) { log.error("ProjectName should be defined in systemRuntime.properties as 'systemRuntime.projectName'"); } else { initProjectName(projectName); } logVersion(); initExecutorServiceShutdownHook(); SystemRuntime.setRuntime(this); isInit = true; } else { log.warn("SystemRuntime has already been initialized!"); } }
/** * Convenience method that simplifies retrieval of a thread-bound Subject. If there is no * Subject bound to the thread, this method returns <tt>null</tt>. It is merely a convenient wrapper * for the following: * <p/> * <code>return (Subject)get( SUBJECT_KEY );</code> * <p/> * This method only returns the bound value if it exists - it does not remove it * from the thread. To remove it, one must call {@link #unbindSubject() unbindSubject()} instead. * * @return the Subject object bound to the thread, or <tt>null</tt> if there isn't one bound. * @since 0.2 */ public static Subject getSubject() { return (Subject) get(SUBJECT_KEY); }
/** * Convenience method that simplifies removal of a thread-local Subject from the thread. * <p/> * The implementation just helps reduce casting and remembering of the ThreadContext key name, i.e it is * merely a conveient wrapper for the following: * <p/> * <code>return (Subject)remove( SUBJECT_KEY );</code> * <p/> * If you wish to just retrieve the object from the thread without removing it (so it can be retrieved later during * thread execution), you should use the {@link #getSubject() getSubject()} method for that purpose. * * @return the Subject object previously bound to the thread, or <tt>null</tt> if there was none bound. * @since 0.2 */ public static Subject unbindSubject() { return (Subject) remove(SUBJECT_KEY); }
private Status checkDeploymentStatus(Deployment.Environment environment, String botId, Integer version) { try { IBot bot = botFactory.getBot(environment, botId, version); if (bot != null) { return bot.getDeploymentStatus(); } else { return Status.NOT_FOUND; } } catch (ServiceException e) { return throwError(botId, version, e, "Error while deploying bot! (botId=%s , version=%s)"); } }
/** * Convenience method that simplifies binding a Subject to the ThreadContext. * <p/> * <p>The method's existence is to help reduce casting in your own code and to simplify remembering of * ThreadContext key names. The implementation is simple in that, if the Subject is not <tt>null</tt>, * it binds it to the thread, i.e.: * <p/> * <pre> * if (subject != null) { * put( SUBJECT_KEY, subject ); * }</pre> * * @param subject the Subject object to bind to the thread. If the argument is null, nothing will be done. * @since 0.2 */ public static void bind(Subject subject) { if (subject != null) { put(SUBJECT_KEY, subject); } }
@Override public <T> ScheduledFuture<?> submitScheduledCallable(final Callable<T> callable, long delay, TimeUnit timeUnit, final Map<Object, Object> threadBindings) { return executorService.schedule(() -> { submitCallable(callable, threadBindings); }, delay, timeUnit); }
private void initProjectName(String projectName) { System.setProperty("systemRuntime.projectName", lowerCaseFirstLetter(projectName)); }
@Override public void logVersion() { log.info(projectName + " v" + getVersion()); }
private Integer getLatestDeployedBotVersion(String botId) throws ServiceException { return botFactory.getLatestBot(unrestricted, botId) != null ? botFactory.getLatestBot(unrestricted, botId).getBotVersion() : Integer.valueOf(1); }
@Override public ObjectMapper getContext(Class<?> type) { return DependencyInjector.getInstance().getInstance(ObjectMapper.class); } }
/** * Convenience method that simplifies retrieval of the application's SecurityManager instance from the current * thread. If there is no SecurityManager bound to the thread (probably because framework code did not bind it * to the thread), this method returns <tt>null</tt>. * <p/> * It is merely a convenient wrapper for the following: * <p/> * <code>return (SecurityManager)get( SECURITY_MANAGER_KEY );</code> * <p/> * This method only returns the bound value if it exists - it does not remove it * from the thread. To remove it, one must call {@link #unbindSecurityManager() unbindSecurityManager()} instead. * * @return the Subject object bound to the thread, or <tt>null</tt> if there isn't one bound. * @since 0.9 */ public static SecurityManager getSecurityManager() { return (SecurityManager) get(SECURITY_MANAGER_KEY); }
/** * Convenience method that simplifies removal of the application's SecurityManager instance from the thread. * <p/> * The implementation just helps reduce casting and remembering of the ThreadContext key name, i.e it is * merely a conveient wrapper for the following: * <p/> * <code>return (SecurityManager)remove( SECURITY_MANAGER_KEY );</code> * <p/> * If you wish to just retrieve the object from the thread without removing it (so it can be retrieved later * during thread execution), use the {@link #getSecurityManager() getSecurityManager()} method instead. * * @return the application's SecurityManager instance previously bound to the thread, or <tt>null</tt> if there * was none bound. * @since 0.9 */ public static SecurityManager unbindSecurityManager() { return (SecurityManager) remove(SECURITY_MANAGER_KEY); }
/** * Convenience method that simplifies binding the application's SecurityManager instance to the ThreadContext. * <p/> * <p>The method's existence is to help reduce casting in code and to simplify remembering of * ThreadContext key names. The implementation is simple in that, if the SecurityManager is not <tt>null</tt>, * it binds it to the thread, i.e.: * <p/> * <pre> * if (securityManager != null) { * put( SECURITY_MANAGER_KEY, securityManager); * }</pre> * * @param securityManager the application's SecurityManager instance to bind to the thread. If the argument is * null, nothing will be done. * @since 0.9 */ public static void bind(SecurityManager securityManager) { if (securityManager != null) { put(SECURITY_MANAGER_KEY, securityManager); } }
public DocumentDescriptorInterceptor() { DependencyInjector injector = DependencyInjector.getInstance(); this.userStore = injector.getInstance(IUserStore.class); this.documentDescriptorStore = injector.getInstance(IDocumentDescriptorStore.class); this.conversationDescriptorStore = injector.getInstance(IConversationDescriptorStore.class); this.testCaseDescriptorStore = injector.getInstance(ITestCaseDescriptorStore.class); }
private void bindUserDataToThread(User user) throws IResourceStore.ResourceStoreException, IResourceStore.ResourceNotFoundException { String username = user.getUsername(); ThreadContext.put("currentuser:userid", userStore.searchUser(username)); ThreadContext.put("currentuser:displayname", user.getDisplayName()); ThreadContext.put("currentuser:username", username); }