📄 rmiconnector.java
字号:
} public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException { if (logger.debugOn()) logger.debug("removeNotificationListener" + "(ObjectName,ObjectName,NotificationFilter,Object)", "name=" + name + ", listener=" + listener + ", filter=" + filter + ", handback=" + handback); final MarshalledObject sFilter = new MarshalledObject(filter); final MarshalledObject sHandback = new MarshalledObject(handback); final ClassLoader old = pushDefaultClassLoader(); try { connection.removeNotificationListener(name, listener, sFilter, sHandback, delegationSubject); } catch (IOException ioe) { communicatorAdmin.gotIOException(ioe); connection.removeNotificationListener(name, listener, sFilter, sHandback, delegationSubject); } finally { popDefaultClassLoader(old); } } // Specific Notification Handle ---------------------------------- public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, IOException { final boolean debug = logger.debugOn(); if (debug) logger.debug("addNotificationListener" + "(ObjectName,NotificationListener,"+ "NotificationFilter,Object)", "name=" + name + ", listener=" + listener + ", filter=" + filter + ", handback=" + handback); final Integer listenerID = addListenerWithSubject(name, new MarshalledObject(filter), delegationSubject,true); rmiNotifClient.addNotificationListener(listenerID, name, listener, filter, handback, delegationSubject); } public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException, IOException { final boolean debug = logger.debugOn(); if (debug) logger.debug("removeNotificationListener"+ "(ObjectName,NotificationListener)", "name=" + name + ", listener=" + listener); final Integer[] ret = rmiNotifClient.removeNotificationListener(name, listener); if (debug) logger.debug("removeNotificationListener", "listenerIDs=" + objects(ret)); final ClassLoader old = pushDefaultClassLoader(); try { connection.removeNotificationListeners(name, ret, delegationSubject); } catch (IOException ioe) { communicatorAdmin.gotIOException(ioe); connection.removeNotificationListeners(name, ret, delegationSubject); } finally { popDefaultClassLoader(old); } } public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException { final boolean debug = logger.debugOn(); if (debug) logger.debug("removeNotificationListener"+ "(ObjectName,NotificationListener,"+ "NotificationFilter,Object)", "name=" + name + ", listener=" + listener + ", filter=" + filter + ", handback=" + handback); final Integer ret = rmiNotifClient.removeNotificationListener(name, listener, filter, handback); if (debug) logger.debug("removeNotificationListener", "listenerID=" + ret); final ClassLoader old = pushDefaultClassLoader(); try { connection.removeNotificationListeners(name, new Integer[] {ret}, delegationSubject); } catch (IOException ioe) { communicatorAdmin.gotIOException(ioe); connection.removeNotificationListeners(name, new Integer[] {ret}, delegationSubject); } finally { popDefaultClassLoader(old); } } } //-------------------------------------------------------------------- private class RMINotifClient extends ClientNotifForwarder { public RMINotifClient(ClassLoader cl, Map env) { super(cl, env); } protected NotificationResult fetchNotifs(long clientSequenceNumber, int maxNotifications, long timeout) throws IOException, ClassNotFoundException { IOException org; while (true) { // used for a successful re-connection try { return connection.fetchNotifications(clientSequenceNumber, maxNotifications, timeout); } catch (IOException ioe) { org = ioe; // inform of IOException try { communicatorAdmin.gotIOException(ioe); // The connection should be re-established. continue; } catch (IOException ee) { // No more fetch, the Exception will be re-thrown. break; } // never reached } // never reached } // specially treating for an UnmarshalException if (org instanceof UnmarshalException) { UnmarshalException ume = (UnmarshalException)org; if (ume.detail instanceof ClassNotFoundException) throw (ClassNotFoundException) ume.detail; /* In Sun's RMI implementation, if a method return contains an unserializable object, then we get UnmarshalException wrapping WriteAbortedException wrapping NotSerializableException. In that case we extract the NotSerializableException so that our caller can realize it should try to skip past the notification that presumably caused it. It's not certain that every other RMI implementation will generate this exact exception sequence. If not, we will not detect that the problem is due to an unserializable object, and we will stop trying to receive notifications from the server. It's not clear we can do much better. */ if (ume.detail instanceof WriteAbortedException) { WriteAbortedException wae = (WriteAbortedException) ume.detail; if (wae.detail instanceof IOException) throw (IOException) wae.detail; } } else if (org instanceof MarshalException) { // IIOP will throw MarshalException wrapping a NotSerializableException // when a server fails to serialize a response. MarshalException me = (MarshalException)org; if (me.detail instanceof NotSerializableException) { throw (NotSerializableException)me.detail; } } // Not serialization problem, simply re-throw the orginal exception throw org; } protected Integer addListenerForMBeanRemovedNotif() throws IOException, InstanceNotFoundException { MarshalledObject sFilter = null; NotificationFilterSupport clientFilter = new NotificationFilterSupport(); clientFilter.enableType( MBeanServerNotification.UNREGISTRATION_NOTIFICATION); sFilter = new MarshalledObject(clientFilter); Integer[] listenerIDs; final ObjectName[] names = new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME}; final MarshalledObject[] filters = new MarshalledObject[] {sFilter}; final Subject[] subjects = new Subject[] {null}; try { listenerIDs = connection.addNotificationListeners(names, filters, subjects); } catch (IOException ioe) { communicatorAdmin.gotIOException(ioe); listenerIDs = connection.addNotificationListeners(names, filters, subjects); } return listenerIDs[0]; } protected void removeListenerForMBeanRemovedNotif(Integer id) throws IOException, InstanceNotFoundException, ListenerNotFoundException { try { connection.removeNotificationListeners( MBeanServerDelegate.DELEGATE_NAME, new Integer[] {id}, null); } catch (IOException ioe) { communicatorAdmin.gotIOException(ioe); connection.removeNotificationListeners( MBeanServerDelegate.DELEGATE_NAME, new Integer[] {id}, null); } } protected void lostNotifs(String message, long number) { final String notifType = JMXConnectionNotification.NOTIFS_LOST; final JMXConnectionNotification n = new JMXConnectionNotification(notifType, RMIConnector.this, connectionId, clientNotifCounter++, message, new Long(number)); sendNotification(n); } } private class RMIClientCommunicatorAdmin extends ClientCommunicatorAdmin { public RMIClientCommunicatorAdmin(long period) { super(period); } public void gotIOException (IOException ioe) throws IOException { if (ioe instanceof NoSuchObjectException) { // need to restart super.gotIOException(ioe); return; } // check if the connection is broken try { connection.getDefaultDomain(null); } catch (IOException ioexc) { boolean toClose = false; synchronized(this) { if (!terminated) { terminated = true; toClose = true; } } if (toClose) { // we should close the connection, // but send a failed notif at first final Notification failedNotif = new JMXConnectionNotification( JMXConnectionNotification.FAILED, this, connectionId, clientNotifSeqNo++, "Failed to communicate with the server: "+ioe.toString(), ioe); sendNotification(failedNotif); try { close(true); } catch (Exception e) { // OK. // We are closing } } } // forward the exception if (ioe instanceof ServerException) { /* Need to unwrap the exception. Some user-thrown exception at server side will be wrapped by rmi into a ServerException. For example, a RMIConnnectorServer will wrap a ClassNotFoundException into a UnmarshalException, and rmi will throw a ServerException at client side which wraps this UnmarshalException. No failed notif here. */ Throwable tt = ((ServerException)ioe).detail; if (tt instanceof IOException) { throw (IOException)tt; } else if (tt instanceof RuntimeException) { throw (RuntimeException)tt; } } throw ioe; } public void reconnectNotificationListeners(ClientListenerInfo[] old) throws IOException { final int len = old.length; int i; ClientListenerInfo[] clis = new ClientListenerInfo[len]; final Subject[] subjects = new Subject[len]; final ObjectName[] names = new ObjectName[len]; final NotificationListener[] listeners = new NotificationListener[len]; final NotificationFilter[] filters = new NotificationFilter[len]; final MarshalledObject[] mFilters = new MarshalledObject[len]; final Object[] handbacks = new Object[len]; for (i=0;i<len;i++) { subjects[i] = old[i].getDelegationSubject(); names[i] = old[i].getObjectName(); listeners[i] = old[i].getListener(); filters[i] = old[i].getNotificationFilter(); mFilters[i] = new MarshalledObject(filters[i]); handbacks[i] = old[i].getHandback(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -