/** * Create new instance of {@link ComponentProviderService}. * <p> * Contains *only* {@link DefaultComponentProvider}. Used for creating client instances (CDI/EJB container are * often confused and using them to retrieve instances leads to unstable results since the injection scope is not * properly defined for these cases). See https://java.net/jira/browse/WEBSOCKET_SPEC-197 and * https://java.net/jira/browse/WEBSOCKET_SPEC-196. * * @return initialized {@link ComponentProviderService}. */ public static ComponentProviderService createClient() { return new ComponentProviderService( Collections.unmodifiableList(Arrays.<ComponentProvider>asList(new DefaultComponentProvider()))); }
public TyrusServerEndpointConfigurator() { this.componentProviderService = ComponentProviderService.create(); }
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { //noinspection unchecked return (T) componentProviderService.getEndpointInstance(endpointClass); } }
/** * This method is called by the container each time a new client * connects to the logical endpoint this configurator configures. * Developers may override this method to control instantiation of * endpoint instances in order to customize the initialization * of the endpoint instance, or manage them in some other way. * If the developer overrides this method, services like * dependency injection that are otherwise supported, for example, when * the implementation is part of the Java EE platform * may not be available. * The platform default implementation of this method returns a new * endpoint instance per call, thereby ensuring that there is one * endpoint instance per client, the default deployment cardinality. * * @param endpointClass the class of the endpoint. * @param <T> the type of the endpoint. * @return an instance of the endpoint that will handle all * interactions from a new client. * @throws InstantiationException if there was an error producing the * endpoint instance. * @see javax.websocket.server.ServerEndpointConfig.Configurator#getEndpointInstance(Class) */ public <T> Object getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return getInstance(endpointClass); } }
: componentProvider.getInstance(endpointClass, session, collector); componentProvider.removeSession(session); sessionListener.onClose(session, closeReason);
Map.Entry<Integer, Class<?>> entry = unknownParams.entrySet().iterator().next(); extractors[entry.getKey()] = new ParamValue(0); handlerFactory = new WholeHandler(componentProvider.getInvocableMethod(m), extractors, entry.getValue(), maxMessageSize); messageHandlerFactories.add(handlerFactory); extractors[last.getKey()] = new ParamValue(1); if (last.getValue() == boolean.class || last.getValue() == Boolean.class) { handlerFactory = new PartialHandler(componentProvider.getInvocableMethod(m), extractors, message.getValue(), maxMessageSize); messageHandlerFactories.add(handlerFactory); this.onOpenMethod = onOpen == null ? null : componentProvider.getInvocableMethod(onOpen); this.onErrorMethod = onError == null ? null : componentProvider.getInvocableMethod(onError); this.onCloseMethod = onClose == null ? null : componentProvider.getInvocableMethod(onClose); this.onOpenParameters = onOpenParameters; this.onErrorParameters = onErrorParameters;
void onClose(CloseReason closeReason, Session session) { try { if (onCloseMethod != null) { callMethod(onCloseMethod, onCloseParameters, session, true, closeReason); } } finally { componentProvider.removeSession(session); } }
private <T> Object getCoderInstance(Session session, CoderWrapper<T> wrapper) { final Object coder = wrapper.getCoder(); if (coder == null) { ErrorCollector collector = new ErrorCollector(); final Object coderInstance = this.componentProvider .getCoderInstance(wrapper.getCoderClass(), session, getEndpointConfig(), collector); if (!collector.isEmpty()) { final DeploymentException deploymentException = collector.composeComprehensiveException(); LOGGER.log(Level.WARNING, deploymentException.getMessage(), deploymentException); return null; } return coderInstance; } return coder; }
private ClientManager(String containerProviderClassName, WebSocketContainer webSocketContainer) { final ErrorCollector collector = new ErrorCollector(); componentProvider = ComponentProviderService.createClient(); Class engineProviderClazz; try {
/** * This method is called by the container each time a new client * connects to the logical endpoint this configurator configures. * Developers may override this method to control instantiation of * endpoint instances in order to customize the initialization * of the endpoint instance, or manage them in some other way. * If the developer overrides this method, services like * dependency injection that are otherwise supported, for example, when * the implementation is part of the Java EE platform * may not be available. * The platform default implementation of this method returns a new * endpoint instance per call, thereby ensuring that there is one * endpoint instance per client, the default deployment cardinality. * * @param endpointClass the class of the endpoint. * @param <T> the type of the endpoint. * @return an instance of the endpoint that will handle all * interactions from a new client. * @throws InstantiationException if there was an error producing the * endpoint instance. * @see javax.websocket.server.ServerEndpointConfig.Configurator#getEndpointInstance(Class) */ public <T> Object getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return getInstance(endpointClass); } }
: componentProvider.getInstance(endpointClass, session, collector); componentProvider.removeSession(session); sessionListener.onClose(session, closeReason);
Map.Entry<Integer, Class<?>> entry = unknownParams.entrySet().iterator().next(); extractors[entry.getKey()] = new ParamValue(0); handlerFactory = new WholeHandler(componentProvider.getInvocableMethod(m), extractors, entry.getValue(), maxMessageSize); messageHandlerFactories.add(handlerFactory); extractors[last.getKey()] = new ParamValue(1); if (last.getValue() == boolean.class || last.getValue() == Boolean.class) { handlerFactory = new PartialHandler(componentProvider.getInvocableMethod(m), extractors, message.getValue(), maxMessageSize); messageHandlerFactories.add(handlerFactory); this.onOpenMethod = onOpen == null ? null : componentProvider.getInvocableMethod(onOpen); this.onErrorMethod = onError == null ? null : componentProvider.getInvocableMethod(onError); this.onCloseMethod = onClose == null ? null : componentProvider.getInvocableMethod(onClose); this.onOpenParameters = onOpenParameters; this.onErrorParameters = onErrorParameters;
void onClose(CloseReason closeReason, Session session) { try { if (onCloseMethod != null) { callMethod(onCloseMethod, onCloseParameters, session, true, closeReason); } } finally { componentProvider.removeSession(session); } }
private <T> Object getCoderInstance(Session session, CoderWrapper<T> wrapper) { final Object coder = wrapper.getCoder(); if (coder == null) { ErrorCollector collector = new ErrorCollector(); final Object coderInstance = this.componentProvider .getCoderInstance(wrapper.getCoderClass(), session, getEndpointConfig(), collector); if (!collector.isEmpty()) { final DeploymentException deploymentException = collector.composeComprehensiveException(); LOGGER.log(Level.WARNING, deploymentException.getMessage(), deploymentException); return null; } return coderInstance; } return coder; }
private ClientManager(String containerProviderClassName, WebSocketContainer webSocketContainer) { final ErrorCollector collector = new ErrorCollector(); componentProvider = ComponentProviderService.createClient(); Class engineProviderClazz; try {
loaded = classObjectMap.get(c); } else { loaded = getInstance(c); if (loaded != null) { if (loaded instanceof Encoder) { loaded = getInstance(c); if (loaded != null) { if (loaded instanceof Encoder) {
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { //noinspection unchecked return (T) componentProviderService.getEndpointInstance(endpointClass); } }
/** * Create new instance of {@link ComponentProviderService}. * <p> * Contains *only* {@link DefaultComponentProvider}. Used for creating client instances (CDI/EJB container are * often confused and using them to retrieve instances leads to unstable results since the injection scope is not * properly defined for these cases). See https://java.net/jira/browse/WEBSOCKET_SPEC-197 and * https://java.net/jira/browse/WEBSOCKET_SPEC-196. * * @return initialized {@link ComponentProviderService}. */ public static ComponentProviderService createClient() { return new ComponentProviderService( Collections.unmodifiableList(Arrays.<ComponentProvider>asList(new DefaultComponentProvider()))); }
this.onError = onErrorMethod; } else { this.onOpen = componentProvider.getInvocableMethod(onOpenMethod); this.onClose = componentProvider.getInvocableMethod(onCloseMethod); this.onError = componentProvider.getInvocableMethod(onErrorMethod);
public TyrusServerEndpointConfigurator() { this.componentProviderService = ComponentProviderService.create(); }