Package org.mc4j.ems.connection

Examples of org.mc4j.ems.connection.EmsConnectException


    protected void doConnect() {

        Integer vmid = Integer.parseInt(this.connectionSettings.getServerUrl());
        LocalVirtualMachine lvm = LocalVMConnector.getAllMonitorableVirtualMachines().get(vmid);
        if (lvm == null) {
            throw new EmsConnectException("Couldn't find VirtualMachine with id " + vmid);
        }

        if (!lvm.isManageable()) {
            try {
                LocalVMConnector.startManagementAgent(lvm);
            } catch (IOException e) {
                throw new EmsConnectException("Couldn't make vm manageable through agent attachment",e);
            }
        }
        connectionSettings.setServerUrl(lvm.getConnectorAddress());

        super.doConnect();
View Full Code Here


        } else {
            method = serverClass.getMethod(m.getName(),m.getParameterTypes());
        }

        if (method == null) {
            throw new EmsConnectException("Unsupported operation [" + m.getName() + "]");
        }

        ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
        try {
            roundTrips++;
//            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            if (this.provider instanceof JBossConnectionProvider) {                  
                JBossConnectionProvider jbossProvider = (JBossConnectionProvider) this.provider;
                // See https://jira.jboss.org/jira/browse/JOPR-9 for an explanation of why we have to re-set the
                // PrincipalInfo prior to every JBoss JMX call.                
                jbossProvider.resetPrincipalInfo();
            }
            return method.invoke(this.remoteServer, args);
        } catch(InvocationTargetException e) {
            failures++;
            if (e.getCause() != null) {
                Throwable t = e.getCause();
                if (t instanceof java.rmi.ConnectException) {
                    throw new EmsConnectException(t);
                } else if (t instanceof NoSuchObjectException) {
                    // This happens when the server comes back up and the stub is stale
                    // try to reconnect if this provider supports it (if it told the proxy what the provider was)
                    if (provider != null && !reconnecting) {
                        try {
                            log.info("Reestablishing RMI stub " + this.provider.getConnectionSettings().getServerUrl());
                            reconnecting = true;
                            provider.connect();
                            // Retry the request once
                            return this.invoke(proxy, m, args);
                        } catch(Exception f) {
                            log.warn("Unable to reestablish RMI stub to restarted server.",f);
                        } finally{ reconnecting = false; }
                    }
                    // The reconnect failed, throw the original exception
                    // If the retry fails, it will throw its own exception
                    throw new EmsConnectException(t);
                } else if (t instanceof java.io.IOException) {
                    throw new EmsConnectException(t);
                } else if (t instanceof NotSerializableException) {
                    throw new EmsUnsupportedTypeException("Value was not serializable " + t.getLocalizedMessage(),t);
                } else {
                    throw new EmsConnectException("Connection failure " + t.getLocalizedMessage(), t);
                }
            } else {
                throw e;
            }
        } catch (Exception e) {
View Full Code Here

                        entries.add(getCachedTempForFile(file,tempDir));
                    } else {
                        entries.add(file.toURI().toURL());
                    }
                } catch (MalformedURLException e) {
                    throw new EmsConnectException("Unable to read class path library url", e);
                }
            }
        }

        // Now load in the implementation jar
        // URL implURL = new URL(null, "deepjar://org-mc4j-ems-impl.jar", new Handler());
        URL implURL = storeImplToTemp("org-mc4j-ems-impl.jar", tempDir);

        entries.add(implURL);


        if (settings.getConnectionType() instanceof LocalVMTypeDescriptor) {
            // Need tools.jar if its not already loaded
            try {
                Class.forName("com.sun.tools.attach.VirtualMachine");
            } catch (ClassNotFoundException e) {
                // Try to load tools.jar
                File toolsJar = null;
                toolsJar = findToolsJarForHome(System.getProperty("java.home"));
                if (toolsJar == null) {
                    toolsJar = findToolsJarForHome(System.getProperty("env_java_home"));
                }

                if (toolsJar != null) {
                    try {
                        log.debug("Found tools.jar at " + toolsJar.getPath());
                        entries.add(toolsJar.toURI().toURL());
                    } catch (MalformedURLException e1) { /* Unnexpected */ }
                } else {
                    throw new EmsConnectException("Unable to find tools.jar. Add it to your classpath to use Sun local vm connections.");
                }
            }
        }


View Full Code Here

TOP

Related Classes of org.mc4j.ems.connection.EmsConnectException

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.