public HttpClientImpl(Gson gson, HttpURLConnectionFactory httpURLConnectionFactory, ClientConfiguration configuration) { this.gson = Assert.requireNonNull(gson, "gson"); this.httpURLConnectionFactory = Assert.requireNonNull(httpURLConnectionFactory, "httpURLConnectionFactory"); this.configuration = configuration; }
/** * Constructor * * @param onRemoveCallback callback that will be called for each garbage collection call. */ public GarbageCollector(RemotingConfiguration configuration, GarbageCollectionCallback onRemoveCallback) { this.onRemoveCallback = Assert.requireNonNull(onRemoveCallback, "onRemoveCallback"); this.configuration = Assert.requireNonNull(configuration, "configuration"); }
public <T> T getInstance(Class<T> cls) { Assert.requireNonNull(cls, "cls"); return (T) instances.get(cls); } }
private <T extends Command> void registerCommand(final ActionRegistry registry, final Class<T> commandClass, final Callback<T> handler) { Assert.requireNonNull(registry, "registry"); Assert.requireNonNull(commandClass, "commandClass"); Assert.requireNonNull(handler, "handler"); registry.register(commandClass, new CommandHandler() { @Override public void handleCommand(final Command command, final List response) { LOG.trace("Handling {} for DolphinContext {}", commandClass.getSimpleName(), getId()); handler.call((T) command); } }); }
@Override public void addResponseHandler(final HttpURLConnectionHandler handler) { Assert.requireNonNull(handler, "handler"); responseHandlers.add(handler); }
@Override public void sessionDestroyed(final HttpSessionEvent sessionEvent) { Assert.requireNonNull(sessionEvent, "sessionEvent"); final HttpSession session = sessionEvent.getSession(); Assert.requireNonNull(session, "session"); sessionMutexMap.remove(session.getId()); }
public RemotingContextImpl(final DolphinContext dolphinContext, DolphinEventBus eventBus) { this.dolphinContext = Assert.requireNonNull(dolphinContext, "dolphinContext"); this.eventBus = Assert.requireNonNull(eventBus, "eventBus"); clientSessionExecutor = new ClientSessionExecutorImpl(new Executor() { @Override public void execute(Runnable command) { dolphinContext.runLater(command); } }); }
@Override public void handle(final HttpURLConnection response) { Assert.requireNonNull(response, "response"); if(this.url.equals(response.getURL())) { String clientIdInHeader = response.getHeaderField(PlatformConstants.CLIENT_ID_HTTP_HEADER_NAME); if (clientIdInHeader == null) { throw new RuntimeException("No client id found in response"); } } } }
private synchronized Lock getOrCreateClientSessionLockForHttpSession(HttpSession session) { Assert.requireNonNull(session, "session"); if (session.getAttribute(CLIENT_SESSION_LOCK) == null) { session.setAttribute(CLIENT_SESSION_LOCK, new ReentrantLock()); } return (Lock) session.getAttribute(CLIENT_SESSION_LOCK); }
public <T> void provideInstance(Class<T> cls, T instance) { Assert.requireNonNull(cls, "cls"); Assert.requireNonNull(instance, "instance"); if(getInstance(cls) != null) { throw new IllegalStateException("Instance for class " + cls + " already provided"); } instances.put(cls, instance); }
public void sync(final Runnable runnable) throws Exception { Assert.requireNonNull(runnable, "runnable"); sync(new Callable<Void>() { @Override public Void call() throws Exception { runnable.run(); return null; } }); }
@Override public void sessionDestroyed(HttpSessionEvent sessionEvent) { Assert.requireNonNull(sessionEvent, "sessionEvent"); LOG.trace("Http session {} destroyed! Will remove all client sessions for the http session.", sessionEvent.getSession().getId()); clientSessionManager.removeAllClientSessionsInHttpSession(sessionEvent.getSession()); } }
@Override public void call(DolphinContext dolphinContext) { Assert.requireNonNull(dolphinContext, "dolphinContext"); LOG.trace("Destroying DolphinContext {}", dolphinContext.getId()); remove(clientSession); } };
@Override public final S getService(final ClientConfiguration configuration) { Assert.requireNonNull(configuration, "configuration"); creationLock.lock(); try { this.service = createService(configuration); } finally { creationLock.unlock(); } return service; }
@Override public void handle(final HttpURLConnection request) { Assert.requireNonNull(request, "request"); final String clientId = clientSessionStore.getClientIdentifierForUrl(request.getURL()); if (clientId != null) { LOG.debug("Adding client id {} to http request at {}", clientId, request.getURL()); request.setRequestProperty(PlatformConstants.CLIENT_ID_HTTP_HEADER_NAME, clientId); } else { LOG.debug("Request to application at {} without client id. PlatformClient id not defined until now.", request.getURL()); } } }
@Override public void sessionCreated(HttpSessionEvent sessionEvent) { Assert.requireNonNull(sessionEvent, "sessionEvent"); try { sessionEvent.getSession().setMaxInactiveInterval(sessionTimeoutInSeconds); } catch (Exception e) { LOG.warn("Can not set the defined session timeout!", e); } }
@Override protected void doPost(final HttpServletRequest req, final HttpServletResponse response) throws ServletException, IOException { Assert.requireNonNull(response, "response"); final DolphinContext currentContext = dolphinContextProvider.getCurrentDolphinContext(); if(currentContext == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing or wrong client session id"); } else { currentContext.interrupt(); } } }
@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); }
/** * Register a new dolphin session as a MBean * @param session the session * @return the subscription for deregistration */ public Subscription registerDolphinContext(ClientSession session, GarbageCollector garbageCollector) { Assert.requireNonNull(session, "session"); Assert.requireNonNull(garbageCollector, "garbageCollector"); DolphinSessionInfoMBean mBean = new DolphinSessionInfo(session, garbageCollector); return MBeanRegistry.getInstance().register(mBean, new MBeanDescription("com.canoo.dolphin", "DolphinSession", "session")); }
@Override public void handle(final HttpURLConnection connection) { Assert.requireNonNull(connection, "connection"); try { clientCookieHandler.setRequestCookies(connection); } catch (URISyntaxException e) { throw new DolphinRuntimeException("Can not set cookies", e); } } }