/** * Default constructor * @param name name of the param * @param value value of the param */ public Param(String name, Object value) { this.name = Assert.requireNonBlank(name, "name"); this.value = value; }
/** * Returns the controller class that is registered for the given name. For more information about controller * classes and the name definition see {@link DolphinController} * @param name the name * @return the controller class */ public synchronized Class<?> getControllerClassForName(String name) { Assert.requireNonBlank(name, "name"); Class<?> foundClass = controllersClasses.get(name); if(foundClass == null) { throw new IllegalArgumentException("Can't find controller type with name " + name); } return foundClass; } }
public DolphinContext getContextById(String clientSessionId) { Assert.requireNonBlank(clientSessionId, "clientSessionId"); WeakReference<DolphinContext> ref = weakContextMap.get(clientSessionId); DolphinContext dolphinContext = ref.get(); Assert.requireNonNull(dolphinContext, "dolphinContext"); return dolphinContext; }
private void onDestroyController(final String controllerId) { Assert.requireNonBlank(controllerId, "controllerId"); if (platformBeanRepository == null) { throw new IllegalStateException("An action was called before the init-command was sent."); } controllerHandler.destroyController(controllerId); }
public Mutex getMutexForHttpSession(final String sessionId) { Assert.requireNonBlank(sessionId, "sessionId"); final WeakReference<Mutex> mutexReference = sessionMutexMap.get(sessionId); Assert.requireNonNull(mutexReference, "mutexReference"); return mutexReference.get(); } }
public Mutex getMutexForClientSession(final String sessionId) { Assert.requireNonBlank(sessionId, "sessionId"); final WeakReference<Mutex> mutexReference = sessionMutexMap.get(sessionId); Assert.requireNonNull(mutexReference, "mutexReference"); return mutexReference.get(); } }
private void onSessionEnds(final String dolphinSessionId) { Assert.requireNonBlank(dolphinSessionId, "dolphinSessionId"); final List<Subscription> subscriptions = sessionStore.get(dolphinSessionId); if (subscriptions != null) { for (Subscription subscription : subscriptions) { subscription.unsubscribe(); } } }
private <T extends Serializable> List<MessageListener<T>> getListenersForSessionAndTopic(final String sessionId, final Topic<T> topic) { Assert.requireNonBlank(sessionId, "sessionId"); Assert.requireNonNull(topic, "topic"); final List<MessageListener<?>> handlers = topicToListenerMap.get(topic); if (handlers == null) { return Collections.emptyList(); } final List<MessageListener<T>> ret = new ArrayList<>(); for (MessageListener<?> listener : handlers) { if (sessionId.equals(listenerToSessionMap.get(listener))) { ret.add((MessageListener<T>) listener); } } return ret; }
@Override public synchronized <T> CompletableFuture<ControllerProxy<T>> createController(final String name) { Assert.requireNonBlank(name, "name"); if(controllerProxyFactory == null) { throw new IllegalStateException("connect was not called!"); } return controllerProxyFactory.<T>create(name).handle(new BiFunction<ControllerProxy<T>, Throwable, ControllerProxy<T>>() { @Override public ControllerProxy<T> apply(ControllerProxy<T> controllerProxy, Throwable throwable) { if (throwable != null) { throw new ControllerInitalizationException(throwable); } return controllerProxy; } }); }
@Override public Object get(final String name, final ObjectFactory<?> objectFactory) { Assert.requireNonBlank(name, "name"); Assert.requireNonNull(objectFactory, "objectFactory"); Map<String, Object> localStore = getLocalStore(); if (!localStore.containsKey(name)) { localStore.put(name, objectFactory.getObject()); } return localStore.get(name); }
@Override public <C> CompletableFuture<ControllerProxy<C>> createController(String name) { Assert.requireNonBlank(name, "name"); return controllerProxyFactory.<C>create(name, getId()).handle(new BiFunction<ControllerProxy<C>, Throwable, ControllerProxy<C>>() { @Override public ControllerProxy<C> apply(ControllerProxy<C> cControllerProxy, Throwable throwable) { if (throwable != null) { throw new ControllerInitalizationException(throwable); } return cControllerProxy; } }); } }
public DolphinContextTaskQueue(final String dolphinSessionId, final ClientSessionProvider sessionProvider, final CommunicationManager communicationManager, final long maxExecutionTime, final TimeUnit maxExecutionTimeUnit) { this.dolphinSessionId = Assert.requireNonBlank(dolphinSessionId, "dolphinSessionId"); this.tasks = new LinkedBlockingQueue<>(); this.communicationManager = Assert.requireNonNull(communicationManager, "communicationManager");; this.sessionProvider = Assert.requireNonNull(sessionProvider, "sessionProvider"); this.maxExecutionTime = maxExecutionTime; this.maxExecutionTimeUnit = Assert.requireNonNull(maxExecutionTimeUnit, "maxExecutionTimeUnit"); }
private void onCallControllerAction(final String controllerId, final String actionName, final Map<String, Object> params) { Assert.requireNonBlank(controllerId, "controllerId"); Assert.requireNonBlank(actionName, "actionName"); Assert.requireNonNull(params, "params"); //TODO: Remove this. Should bve handled by commands. final ServerControllerActionCallBean bean = platformBeanRepository.getControllerActionCallBean(); Assert.requireNonNull(bean, "bean"); if (platformBeanRepository == null) { throw new IllegalStateException("An action was called before the init-command was sent."); } try { controllerHandler.invokeAction(controllerId, actionName, params); } catch (Exception e) { LOG.error("Unexpected exception while invoking action {} on controller {}", actionName, controllerId, e); bean.setError(true); } }
public void destroyController(final String id) { Assert.requireNonBlank(id, "id"); final List<String> childControllerIds = parentChildRelations.remove(id); if(childControllerIds != null && !childControllerIds.isEmpty()) { for(String childControllerId : childControllerIds) { destroyController(childControllerId); } } final Object controller = controllers.remove(id); Assert.requireNonNull(controller, "controller"); final String parentControllerId = childToParentRelations.remove(id); if(parentControllerId != null) { Object parentController = controllers.get(parentControllerId); Assert.requireNonNull(parentController, "parentController"); firePreChildDestroyed(parentController, controller); } final Class controllerClass = controllerClassMapping.remove(id); beanFactory.destroyDependendInstance(controller, controllerClass); final Object model = models.remove(id); if (model != null) { beanRepository.delete(model); } final Subscription subscription = mBeanSubscriptions.remove(id); if(subscription != null) { subscription.unsubscribe(); } }
public String createController(final String name, final String parentControllerId) { Assert.requireNonBlank(name, "name"); final Class<?> controllerClass = controllerRepository.getControllerClassForName(name);
private void onCreateController(final String controllerName, final String parentControllerId) { Assert.requireNonBlank(controllerName, "controllerName"); if (platformBeanRepository == null) { throw new IllegalStateException("An action was called before the init-command was sent."); } //TODO: Remove this. Should be handled by commands. See https://github.com/canoo/dolphin-platform/issues/522 final InternalAttributesBean bean = platformBeanRepository.getInternalAttributesBean(); final String controllerId = controllerHandler.createController(controllerName, parentControllerId); bean.setControllerId(controllerId); Object model = controllerHandler.getControllerModel(controllerId); if (model != null) { bean.setModel(model); } }
public static void register(final ServletContext servletContext, final String mapping) { Assert.requireNonNull(servletContext, "servletContext"); Assert.requireNonBlank(mapping, "mapping"); servletContext.addServlet("remoteValidationServlet", new RemoteValidationServlet()).addMapping(mapping); } }
public <T> CompletableFuture<ControllerProxy<T>> create(String name, String parentControllerId) { Assert.requireNonBlank(name, "name"); final InternalAttributesBean bean = platformBeanRepository.getInternalAttributesBean(); final CreateControllerCommand createControllerCommand = new CreateControllerCommand(); createControllerCommand.setControllerName(name); if(parentControllerId != null) { createControllerCommand.setParentControllerId(parentControllerId); } return dolphinCommandHandler.invokeDolphinCommand(createControllerCommand).thenApply(new Function<Void, ControllerProxy<T>>() { @Override public ControllerProxy<T> apply(Void aVoid) { return new ControllerProxyImpl<T>(bean.getControllerId(), (T) bean.getModel(), clientConnector, platformBeanRepository, ControllerProxyFactory.this, converters); } }); } }
/** * Register a new Dolphin Platform controller as a MBean * @param controllerClass the controller class * @param controllerId the controller id * @param modelProvider the model provider * @return the subscription for deregistration */ public Subscription registerController(Class<?> controllerClass, String controllerId, ModelProvider modelProvider) { Assert.requireNonNull(controllerClass, "controllerClass"); Assert.requireNonBlank(controllerId, "controllerId"); Assert.requireNonNull(modelProvider, "modelProvider"); DolphinControllerInfoMBean mBean = new DolphinControllerInfo(dolphinContextId, controllerClass, controllerId, modelProvider); return MBeanRegistry.getInstance().register(mBean, new MBeanDescription("com.canoo.dolphin", controllerClass.getSimpleName(), "controller")); }
public ControllerProxyImpl(final String controllerId, final T model, final AbstractClientConnector clientConnector, final ClientPlatformBeanRepository platformBeanRepository, final ControllerProxyFactory controllerProxyFactory, final Converters converters) { this.clientConnector = Assert.requireNonNull(clientConnector, "clientConnector"); this.controllerId = Assert.requireNonBlank(controllerId, "controllerId"); this.controllerProxyFactory = Assert.requireNonNull(controllerProxyFactory, "controllerProxyFactory"); this.model = Assert.requireNonNull(model, "model"); this.platformBeanRepository = Assert.requireNonNull(platformBeanRepository, "platformBeanRepository"); this.converters = Assert.requireNonNull(converters, "converters"); }