Pavel Borsuk
Pavel Borsuk

Reputation: 1

Tyrus SHARED_CONTAINER with different PROXY_URI without synchronization

Is this possible to use SHARED_CONTAINER, for connection with different proxy like this, but without use lock

    public static void main(String[] args)
    {
        ClientManager client = ClientManager.createClient();
        client.getProperties().put(ClientProperties.SHARED_CONTAINER, true);
        List<String> hostnames = List.of("proxy1", "proxy2", "proxy3");
        Lock lock = new ReentrantLock();
        Endpoint justEndpoint = new Endpoint() {
            @Override
            public void onOpen(Session session, EndpointConfig endpointConfig) {

            }
        };
        for(String hostname : hostnames)
        {
            new Thread() {
                public void run() {
                    connectWithProxy(lock, client, justEndpoint, hostname);
                }
            }.start();
        }


    }

    private static void connectWithProxy(Lock lock, ClientManager clientManager, Endpoint justEndpoint, String hostname) {
        lock.lock();
        try {
            clientManager.getProperties().put(ClientProperties.PROXY_URI,
                    "https://" + hostname + ":" + 3128);
            clientManager.connectToServer(justEndpoint, ClientEndpointConfig.Builder.create().build(),
                    URI.create("someUrl"));
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            lock.unlock();
        }
    }

I've tried to create a few clientmanager but SHARED_CONTAINER doesn't work in this case

Upvotes: 0

Views: 12

Answers (0)

Related Questions