⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rmiconnector.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	connectionBroadcaster.addNotificationListener(listener, filter,						      handback);    }    public void	removeConnectionNotificationListener(NotificationListener listener)	    throws ListenerNotFoundException {	if (listener == null) 	    throw new NullPointerException("listener");	connectionBroadcaster.removeNotificationListener(listener);    }    public void	removeConnectionNotificationListener(NotificationListener listener,					     NotificationFilter filter,					     Object handback)	    throws ListenerNotFoundException {	if (listener == null) 	    throw new NullPointerException("listener");	connectionBroadcaster.removeNotificationListener(listener, filter,							 handback);    }    private void sendNotification(Notification n) {	connectionBroadcaster.sendNotification(n);    }    public synchronized void close() throws IOException {	close(false);    }    // allows to do close after setting the flag "terminated" to true.    // It is necessary to avoid a deadlock, see 6296324    private synchronized void close(boolean intern) throws IOException {			   	final boolean tracing = logger.traceOn();	final boolean debug   = logger.debugOn();	final String  idstr   = (tracing?"["+this.toString()+"]":null);	if (!intern) {	    // Return if already cleanly closed.	    //	    if (terminated) {		if (closeException == null) {		    if (tracing) logger.trace("close",idstr + " already closed.");		    return;		}	    } else {		terminated = true;	    }	}	if (closeException != null && tracing) {	    // Already closed, but not cleanly. Attempt again.	    //	    if (tracing) {		logger.trace("close",idstr + " had failed: " + closeException);		logger.trace("close",idstr + " attempting to close again.");	    }	}        String savedConnectionId = null;	if (connected) {	    savedConnectionId = connectionId;	}	closeException = null;	if (tracing) logger.trace("close",idstr + " closing.");	if (communicatorAdmin != null) {	    communicatorAdmin.terminate();	}	if (rmiNotifClient != null) {	    try {		rmiNotifClient.terminate();		if (tracing) logger.trace("close",idstr +				    " RMI Notification client terminated.");	    } catch (RuntimeException x) {		closeException = x;		if (tracing) logger.trace("close",idstr +			 " Failed to terminate RMI Notification client: " + x);		if (debug) logger.debug("close",x);	    }	}	if (connection != null) {	    try {		connection.close();		if (tracing) logger.trace("close",idstr + " closed.");	    } catch (NoSuchObjectException nse) {		// OK, the server maybe closed itself.	    } catch (IOException e) {		closeException = e;		if (tracing) logger.trace("close",idstr +					  " Failed to close RMIServer: " + e);		if (debug) logger.debug("close",e);	    }	}	// Clean up MBeanServerConnection table	//	rmbscMap.clear();	/* Send notification of closure.  We don't do this if the user	 * never called connect() on the connector, because there's no	 * connection id in that case.  */	if (savedConnectionId != null) {	    Notification closedNotif =		new JMXConnectionNotification(JMXConnectionNotification.CLOSED,					      this,					      savedConnectionId,					      clientNotifSeqNo++,					      "Client has been closed",					      null);	    sendNotification(closedNotif);	}	// throw exception if needed	//	if (closeException != null) {	    if (tracing) logger.trace("close",idstr + " failed to close: " +			       closeException);	    if (closeException instanceof IOException)		throw (IOException) closeException;	    if (closeException instanceof RuntimeException)		throw (RuntimeException) closeException;	    final IOException x =		new IOException("Failed to close: " + closeException);	    throw EnvHelp.initCause(x,closeException);	}    }    // added for re-connection    private Integer addListenerWithSubject(ObjectName name,					   MarshalledObject filter,					   Subject delegationSubject,					   boolean reconnect)	throws InstanceNotFoundException, IOException {	    	final boolean debug = logger.debugOn();	if (debug)	    logger.debug("addListenerWithSubject",			 "(ObjectName,MarshalledObject,Subject)");		    	final ObjectName[] names = new ObjectName[] {name};	final MarshalledObject[] filters = new MarshalledObject[] {filter};	final Subject[] delegationSubjects = new Subject[] {	    delegationSubject	};	final Integer[] listenerIDs =	    addListenersWithSubjects(names,filters,delegationSubjects,					  reconnect);	    	if (debug) logger.debug("addListenerWithSubject","listenerID="				+ listenerIDs[0]);	return listenerIDs[0];    }    // added for re-connection    private Integer[] addListenersWithSubjects(ObjectName[]       names,			     MarshalledObject[] filters,			     Subject[]          delegationSubjects,			     boolean            reconnect) 	throws InstanceNotFoundException, IOException {	final boolean debug = logger.debugOn();	if (debug)	logger.debug("addListenersWithSubjects",			 "(ObjectName[],MarshalledObject[],Subject[])");	final ClassLoader old = pushDefaultClassLoader();	Integer[] listenerIDs = null;	try {	    listenerIDs = connection.addNotificationListeners(names,							      filters,							  delegationSubjects);	} catch (NoSuchObjectException noe) {	    // maybe reconnect	    if (reconnect) {		communicatorAdmin.gotIOException(noe);				listenerIDs = connection.addNotificationListeners(names,						       filters,						       delegationSubjects);	    } else {		throw noe;	    }	} catch (IOException ioe) {	    // send a failed notif if necessary	    communicatorAdmin.gotIOException(ioe);	} finally {	    popDefaultClassLoader(old);	}	    	if (debug) logger.debug("addListenersWithSubjects","registered "				+ listenerIDs.length + " listener(s)");	return listenerIDs;    }    //--------------------------------------------------------------------    // Implementation of MBeanServerConnection    //--------------------------------------------------------------------    private class RemoteMBeanServerConnection        implements MBeanServerConnection {	private Subject delegationSubject;	public RemoteMBeanServerConnection() {	    this(null);	}	public RemoteMBeanServerConnection(Subject delegationSubject) {	    this.delegationSubject = delegationSubject;	}        public ObjectInstance createMBean(String className,                                          ObjectName name)                throws ReflectionException,                       InstanceAlreadyExistsException,                       MBeanRegistrationException,                       MBeanException,                       NotCompliantMBeanException,                       IOException {	    if (logger.debugOn()) 		logger.debug("createMBean(String,ObjectName)",			     "className=" + className + ", name=" +			     name);            final ClassLoader old = pushDefaultClassLoader();            try {                return connection.createMBean(className,					     name,					     delegationSubject);	    } catch (IOException ioe) {		communicatorAdmin.gotIOException(ioe);                return connection.createMBean(className,					     name,					     delegationSubject);            } finally {                popDefaultClassLoader(old);            }        }        public ObjectInstance createMBean(String className,                                          ObjectName name,                                          ObjectName loaderName)            throws ReflectionException,                       InstanceAlreadyExistsException,                       MBeanRegistrationException,                       MBeanException,                       NotCompliantMBeanException,                       InstanceNotFoundException,                       IOException {	    if (logger.debugOn())		logger.debug("createMBean(String,ObjectName,ObjectName)",		      "className=" + className + ", name="		      + name + ", loaderName="		      + loaderName + ")");            final ClassLoader old = pushDefaultClassLoader();            try {                return connection.createMBean(className,					     name,					     loaderName,					     delegationSubject);	    } catch (IOException ioe) {		communicatorAdmin.gotIOException(ioe);                return connection.createMBean(className,					     name,					     loaderName,					     delegationSubject);            } finally {                popDefaultClassLoader(old);            }        }        public ObjectInstance createMBean(String className,                                          ObjectName name,                                          Object params[],                                          String signature[])                throws ReflectionException,                       InstanceAlreadyExistsException,                       MBeanRegistrationException,                       MBeanException,                       NotCompliantMBeanException,                       IOException {	    if (logger.debugOn())	       logger.debug("createMBean(String,ObjectName,Object[],String[])",		      "className=" + className + ", name="		      + name + ", params="		      + objects(params) + ", signature="		      + strings(signature));            final MarshalledObject sParams = new MarshalledObject(params);            final ClassLoader old = pushDefaultClassLoader();            try {                return connection.createMBean(className,					     name,					     sParams,					     signature,					     delegationSubject);	    } catch (IOException ioe) {		communicatorAdmin.gotIOException(ioe);                return connection.createMBean(className,					     name,					     sParams,					     signature,					     delegationSubject);            } finally {                popDefaultClassLoader(old);            }        }        public ObjectInstance createMBean(String className,                                          ObjectName name,                                          ObjectName loaderName,                                          Object params[],                                          String signature[])                throws ReflectionException,                       InstanceAlreadyExistsException,                       MBeanRegistrationException,                       MBeanException,                       NotCompliantMBeanException,                       InstanceNotFoundException,                       IOException {	    if (logger.debugOn()) logger.debug(		"createMBean(String,ObjectName,ObjectName,Object[],String[])",		"className=" + className + ", name=" + name + ", loaderName=" 		+ loaderName + ", params=" + objects(params)		+ ", signature=" + strings(signature));            final MarshalledObject sParams = new MarshalledObject(params);            final ClassLoader old = pushDefaultClassLoader();            try {                return connection.createMBean(className,					     name,					     loaderName,					     sParams,					     signature,					     delegationSubject);	    } catch (IOException ioe) {		communicatorAdmin.gotIOException(ioe);                return connection.createMBean(className,					     name,					     loaderName,					     sParams,					     signature,					     delegationSubject);            } finally {                popDefaultClassLoader(old);            }        }        public void unregisterMBean(ObjectName name)                throws InstanceNotFoundException,                       MBeanRegistrationException,                       IOException {	    if (logger.debugOn()) 		logger.debug("unregisterMBean", "name=" + name);            final ClassLoader old = pushDefaultClassLoader();            try {                connection.unregisterMBean(name, delegationSubject);	    } catch (IOException ioe) {		communicatorAdmin.gotIOException(ioe);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -