You can create a singleton and delegate Configurator#getEndpointInstance
method call to it; or simple static "map" of registered endpoint
instances should work as well:
public class MyConfigurator extends ServerEndpointConfig.Configurator {
private static final Map<Class, Object> endpointInstances = new
ConcurrentHashMap<Class, Object>();
@Override
public <T> T getEndpointInstance(Class<T> endpointClass) throws
InstantiationException {
Object o = endpointInstances.get(endpointClass);
if(o != null) {
return (T)o;
}
return super.getEndpointInstance(endpointClass);
}
public void registerEndpointInstance(Class endpointClass,
Object instance) {
endpointInstances.put(endpointClass, instance);
}
}
Regards,
Pavel
On 22/04/15 17:28, lywilliam.chhim_at_murex.com wrote:
> Hi Pavel,
>
> I have the same issue with the Configurator since a new Configurator is
> created each time a new server is created. For my application I would
> like to be able to create several servers that would listen on
> different port.
>
> I would like something like that:
>
> MyClass instance1 = new MyClass();
> MyClass instance2 = new MyClass();
>
> Server server1 = new Server("localhost", somePort, "", null,
> MyClass.class);
> Server server2 = new Server("localhost", someOtherPort, "", null,
> MyClass.class);
>
> With server1 having a reference to instance1 and server2 havig a
> reference to instance2 respectively.
>
> In that case the question would be, how can I give instance1 to the
> Configurator of server1 and instance2 to the Configurator of server2
> since Tyrus takes care of instanciating the Configurator object as well
> ?
>
> Thanks again,
> Regards.
>
> Ly William