Package net.xeoh.plugins.remotediscovery.impl.common.discoverymanager

Examples of net.xeoh.plugins.remotediscovery.impl.common.discoverymanager.DiscoveryManager


            final String address = ip + ":" + port;
            final int timeout = 500; // 500 ms RemoteAPIImpl if need detailed
            // version...

            final DiscoveryManager newClient = Proxies.newClient(EXPORT_NAME, address, RemoteDiscoveryImpl.class.getClassLoader(), DiscoveryManager.class);

            /*
             * TODO: With this one we still get the message:
             *
             * "org.freshvanilla.net.VanillaDataSocket allocateBuffer
             * INFO: DiscoveryManager: Running low on memory, pausing..."
             *
             * but, there is no TimeoutException....
             *
             * @sa DiscoveredPluginTest.testMultiplePlugins()
             */
            @SuppressWarnings("unused")
            int pingRes = newClient.ping(123321);

            // Execute collection asynchronously (TODO: cache pool usage could be
            // improved)
            final ExecutorService cachePool = Executors.newCachedThreadPool();
            final ExecutorCompletionService<String> ecs = new ExecutorCompletionService(cachePool);
            final Future<String> future = ecs.submit(new Callable<String>() {

                public String call() throws Exception {
                    return AccessController.doPrivileged(new PrivilegedAction<String>() {
                        public String run() {
                            return newClient.toString();
                        }
                    });
                }
            });

            // Wait at most half a second (TODO: Make this configurable)
            try {
                final String string = future.get(timeout, TimeUnit.MILLISECONDS);
                /*
                 * TODO: Probably it is possible to put here some conversion routines... Because it looks like that
                 * only the ExportInfo makes trouble.... Or just make the ExportInfo much better, ie downwards compatible
                 */
                if (string == null || newClient.getVersion() != this.localManager.getVersion()) { return null; }

                return newClient;
            } catch (final InterruptedException e) {
                // TODO: This one is not an error anymore.
                // Interruption is called because we are running cache thread.
View Full Code Here


        // Query all managers
        for (final RemoteManagerEndpoint endpoint : this.remoteManagersEndpoints) {

            // The manager to use ...
            final DiscoveryManager mgr = RemoteDiscoveryImpl.this.getRemoteProxy(endpoint.address.getHostAddress(), endpoint.port);

            // No matter what happens, close the manager
            try {
                if (mgr == null) {
                    this.logger.info("Remote DiscoveryManager at " + endpoint.address.getHostAddress() + ":" + endpoint.port + " did not answer or has not the right version.");
                    continue;
                }

                // TODO: here are probably not the complete information as it was before....
                // RemoteDiscoveryImpl.this.logger.info("Error getting ping time of remote manager " +
                //          endpoint.address + ":" + endpoint.port);
                final AtomicInteger pingTime = getPingTime(mgr, endpoint.address.getHostAddress(), endpoint.port);

                // Query the information (needs to be inside a privileged block, otherwise applets might complain.
                final ExportInfo exportInfo = AccessController.doPrivileged(new PrivilegedAction<ExportInfo>() {
                    public ExportInfo run() {
                        return mgr.getExportInfoFor(plugin.getCanonicalName());
                    }
                });

                // If the plugin in not exported, do nothing
                if (!exportInfo.isExported) continue;
View Full Code Here

        for (Entry entry : lst) {
            this.remoteDiscoveryImpl.syso("cache rem 2");
            // try to establish connection to the discovery manager

            this.remoteDiscoveryImpl.syso("cache rem 3");
            final DiscoveryManager mgr = this.remoteDiscoveryImpl.getRemoteProxy(entry.manager.address.getHostAddress(), entry.manager.port);

            this.remoteDiscoveryImpl.syso("cache rem 4");
            if (null == mgr) {
                this.remoteDiscoveryImpl.syso("cache rem 5");
                // so manager not available. -> remote from cache
                // TODO!!!
                continue;
            }
            this.remoteDiscoveryImpl.syso("cache rem 6");

            // so our manager is available......
            try {
                this.remoteDiscoveryImpl.syso("cache rem 7");
                // TODO: here are probably not the complete information as it was before....
                // RemoteDiscoveryImpl.this.logger.info("Error getting ping time of remote manager " +
                //          endpoint.address + ":" + endpoint.port);
                @SuppressWarnings("unused")
                final AtomicInteger pingTime = this.remoteDiscoveryImpl.getPingTime(mgr, entry.manager.address.getHostAddress(), entry.manager.port);

                this.remoteDiscoveryImpl.syso("cache rem 8");
                // Query the information (needs to be inside a privileged block, otherwise applets might complain.
                final ExportInfo exportInfo = AccessController.doPrivileged(new PrivilegedAction<ExportInfo>() {
                    public ExportInfo run() {
                        return mgr.getExportInfoFor(getPlugin().getCanonicalName());
                    }
                });
                this.remoteDiscoveryImpl.syso("cache rem 9");

                // If the plugin in not exported, do nothing 
View Full Code Here

        final String address = ip + ":" + port;
        final int timeout = 500; // 500 ms RemoteAPIImpl if need detailed version...

        this.logger.status("remoteproxytodiscovery/start", "ip", ip, "port", port);

        final DiscoveryManager newClient = Proxies.newClient(EXPORT_NAME, address, getClass().getClassLoader(), DiscoveryManager.class);

        // Execute collection asynchronously (TODO: cache pool usage could be improved)
        final ExecutorService cachePool = Executors.newCachedThreadPool(RemoteDiscoveryImpl.threadFactory);
        final ExecutorCompletionService<String> ecs = new ExecutorCompletionService(cachePool);
        final Future<String> future = ecs.submit(new Callable<String>() {

            public String call() throws Exception {
                return AccessController.doPrivileged(new PrivilegedAction<String>() {
                    public String run() {
                        return newClient.ping(667) == 667 ? "OK" : null;
                    }
                });
            }
        });
View Full Code Here

        // Query all managers
        for (final RemoteManagerEndpoint endpoint : endpoints) {

            // The manager to use ...
            final DiscoveryManager mgr = getRemoteProxyToDiscoveryManager(endpoint.address.getHostAddress(), endpoint.port);

            // No matter what happens, close the manager
            try {
                if (mgr == null) {
                    this.logger.status("resolve/vanished", "address", endpoint.address.getHostAddress(), "port", endpoint.port);
                    continue;
                }

                //
                final AtomicInteger pingTime = new AtomicInteger(Integer.MAX_VALUE);

                // Get ping time
                AccessController.doPrivileged(new PrivilegedAction<Object>() {
                    public Object run() {
                        try {
                            final long start = System.nanoTime();

                            // Perform the ping
                            mgr.ping(new Random().nextInt());

                            // Obtain the time
                            final long stop = System.nanoTime();
                            final long time = (stop - start) / 1000;

                            // And set it
                            NetworkProbe.this.logger.status("resolve/ping", "time", time);
                            pingTime.set((int) time);
                        } catch (final Exception e) {
                            NetworkProbe.this.logger.status("resolve/exception/ping", "message", e.getMessage());
                        }
                        return null;
                    }
                });

                // Query the information (needs to be inside a privileged block, otherwise applets might complain.
                final ExportInfo exportInfo = AccessController.doPrivileged(new PrivilegedAction<ExportInfo>() {
                    public ExportInfo run() {
                        return mgr.getExportInfoFor(plugin.getCanonicalName());
                    }
                });

                // If the plugin in not exported, do nothing
                if (!exportInfo.isExported) {
View Full Code Here

        final String address = ip + ":" + port;
        final int timeout = 500; // 500 ms RemoteAPIImpl if need detailed version...

        this.logger.fine("Construction proxy to remote endpoint " + address);
        final DiscoveryManager newClient = Proxies.newClient(EXPORT_NAME, address, getClass().getClassLoader(), DiscoveryManager.class);

        // Execute collection asynchronously (TODO: cache pool usage could be improved)
        final ExecutorService cachePool = Executors.newCachedThreadPool(this.threadFactory);
        final ExecutorCompletionService<String> ecs = new ExecutorCompletionService(cachePool);
        final Future<String> future = ecs.submit(new Callable<String>() {

            public String call() throws Exception {
                return AccessController.doPrivileged(new PrivilegedAction<String>() {
                    public String run() {
                        return newClient.ping(667) == 667 ? "OK" : null;
                    }
                });
            }
        });
View Full Code Here

        // Query all managers
        for (final RemoteManagerEndpoint endpoint : endpoints) {

            // The manager to use ...
            final DiscoveryManager mgr = getRemoteProxyToDiscoveryManager(endpoint.address.getHostAddress(), endpoint.port);

            // No matter what happens, close the manager
            try {
                if (mgr == null) {
                    this.logger.info("Remote DiscoveryManager at " + endpoint.address.getHostAddress() + ":" + endpoint.port + " did not answer even though it appears to be there. .");
                    continue;
                }

                //
                final AtomicInteger pingTime = new AtomicInteger(Integer.MAX_VALUE);

                // Get ping time
                AccessController.doPrivileged(new PrivilegedAction<Object>() {
                    public Object run() {
                        try {
                            final long start = System.nanoTime();

                            // Perform the ping
                            mgr.ping(new Random().nextInt());

                            // Obtain the time
                            final long stop = System.nanoTime();
                            final long time = (stop - start) / 1000;

                            // And set it
                            RemoteDiscoveryImpl.this.logger.finer("Ping time to manager was " + time + "µs");
                            pingTime.set((int) time);
                        } catch (Exception e) {
                            RemoteDiscoveryImpl.this.logger.info("Error getting ping time of remote manager " + endpoint.address + ":" + endpoint.port);
                        }
                        return null;
                    }
                });

                // Query the information (needs to be inside a privileged block, otherwise applets might complain.
                final ExportInfo exportInfo = AccessController.doPrivileged(new PrivilegedAction<ExportInfo>() {
                    public ExportInfo run() {
                        return mgr.getExportInfoFor(plugin.getCanonicalName());
                    }
                });

                // If the plugin in not exported, do nothing
                if (!exportInfo.isExported) continue;
View Full Code Here

TOP

Related Classes of net.xeoh.plugins.remotediscovery.impl.common.discoverymanager.DiscoveryManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.