/** * Create a MonitoredHostProvider instance using the given HostIdentifier. * * @param hostId the host identifier for this MonitoredHost * @throws MonitorException Thrown on any error encountered while communicating with the remote * host. */ public MonitoredHostProvider(HostIdentifier hostId) throws MonitorException { this.hostId = hostId; this.listeners = new ArrayList(); this.interval = DEFAULT_POLLING_INTERVAL; this.activeVms = new HashSet(); String rmiName; String sn = serverName; String path = hostId.getPath(); if ((path != null) && (path.length() > 0)) { sn = path; } if (hostId.getPort() != -1) { rmiName = "rmi://" + hostId.getHost() + ":" + hostId.getPort() + sn; } else { rmiName = "rmi://" + hostId.getHost() + sn; } try { remoteHost = (RemoteHost) Naming.lookup(rmiName); } catch (RemoteException e) { /* * rmi registry not available * * Access control exceptions, where the rmi server refuses a * connection based on policy file configuration, come through * here on the client side. Unfortunately, the RemoteException * doesn't contain enough information to determine the true cause * of the exception. So, we have to output a rather generic message. */ String message = "RMI Registry not available at " + hostId.getHost(); if (hostId.getPort() == -1) { message = message + ":" + java.rmi.registry.Registry.REGISTRY_PORT; } else { message = message + ":" + hostId.getPort(); } if (e.getMessage() != null) { throw new MonitorException(message + "\n" + e.getMessage(), e); } else { throw new MonitorException(message, e); } } catch (NotBoundException e) { // no server with given name String message = e.getMessage(); if (message == null) message = rmiName; throw new MonitorException("RMI Server " + message + " not available", e); } catch (MalformedURLException e) { // this is a programming problem e.printStackTrace(); throw new IllegalArgumentException("Malformed URL: " + rmiName); } this.vmManager = new RemoteVmManager(remoteHost); this.timer = new Timer(true); }
/** Lets the model know if any exceptions occur while communicating with the Interpreter JVM. */ private void _handleRemoteException(RemoteException e) { if (e instanceof UnmarshalException) { /* Interpreter JVM has disappeared (perhaps reset); just ignore the error. */ if (e.getCause() instanceof EOFException) return; /* Deals with bug 2688586: Reset during debugging throws UnmarshalException * We may want to extend this to all kinds of SocketExceptions. */ if ((e.getCause() instanceof SocketException) && (e.getCause().getMessage().equals("Connection reset"))) return; } DrJavaErrorHandler.record(e); }
/** * *************************************************************** * * @param ip * @param port * @return */ public ChordMessageInterface rmiChord(String ip, int port) { ChordMessageInterface chord = null; try { Registry registry = LocateRegistry.getRegistry(ip, port); chord = (ChordMessageInterface) (registry.lookup("Chord")); return chord; } catch (RemoteException e) { e.printStackTrace(); } catch (NotBoundException e) { e.printStackTrace(); } return null; }
/** * Construct a client-side proxy that implements the named protocol, talking to a server at the * named address. * * @param protocol protocol * @param clientVersion client's version * @param addr server address * @param ticket security ticket * @param conf configuration * @param factory socket factory * @param rpcTimeout max time for each rpc; 0 means no timeout * @return the proxy * @throws IOException if any error occurs */ @SuppressWarnings("unchecked") public static <T extends VersionedProtocol> ProtocolProxy<T> getProtocolProxy( Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout) throws IOException { T proxy = (T) Proxy.newProxyInstance( protocol.getClassLoader(), new Class[] {protocol}, new Invoker(addr, ticket, conf, factory, rpcTimeout, protocol)); String protocolName = protocol.getName(); try { ProtocolSignature serverInfo = proxy.getProtocolSignature( protocolName, clientVersion, ProtocolSignature.getFingerprint(protocol.getMethods())); return new ProtocolProxy<T>(protocol, proxy, serverInfo.getMethods()); } catch (RemoteException re) { IOException ioe = re.unwrapRemoteException(IOException.class); if (ioe.getMessage() .startsWith(IOException.class.getName() + ": " + NoSuchMethodException.class.getName())) { // Method getProtocolSignature not supported long serverVersion = proxy.getProtocolVersion(protocol.getName(), clientVersion); if (serverVersion == clientVersion) { return new ProtocolProxy<T>(protocol, proxy, null); } throw new VersionMismatch(protocolName, clientVersion, serverVersion, proxy); } throw re; } }
/** * @param argv The parameters passed to this program. * @exception Exception if the filesystem does not exist. * @return 0 on success, non zero on error. */ private int processArgs(String[] argv) throws Exception { if (argv.length < 1) { printUsage(""); return -1; } int exitCode = -1; int i = 0; String cmd = argv[i++]; // // verify that we have enough command line parameters // if ("-geteditsize".equals(cmd)) { if (argv.length != 1) { printUsage(cmd); return exitCode; } } else if ("-checkpoint".equals(cmd)) { if (argv.length != 1 && argv.length != 2) { printUsage(cmd); return exitCode; } if (argv.length == 2 && !"force".equals(argv[i])) { printUsage(cmd); return exitCode; } } exitCode = 0; try { if ("-checkpoint".equals(cmd)) { long size = namenode.getEditLogSize(); if (size >= checkpointSize || argv.length == 2 && "force".equals(argv[i])) { doCheckpoint(); } else { System.err.println( "EditLog size " + size + " bytes is " + "smaller than configured checkpoint " + "size " + checkpointSize + " bytes."); System.err.println("Skipping checkpoint."); } } else if ("-geteditsize".equals(cmd)) { long size = namenode.getEditLogSize(); System.out.println("EditLog size is " + size + " bytes"); } else { exitCode = -1; LOG.error(cmd.substring(1) + ": Unknown command"); printUsage(""); } } catch (RemoteException e) { // // This is a error returned by hadoop server. Print // out the first line of the error mesage, ignore the stack trace. exitCode = -1; try { String[] content; content = e.getLocalizedMessage().split("\n"); LOG.error(cmd.substring(1) + ": " + content[0]); } catch (Exception ex) { LOG.error(cmd.substring(1) + ": " + ex.getLocalizedMessage()); } } catch (IOException e) { // // IO exception encountered locally. // exitCode = -1; LOG.error(cmd.substring(1) + ": " + e.getLocalizedMessage()); } finally { // Does the RPC connection need to be closed? } return exitCode; }