📄 destination.java
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2001 - 2006 ScalAgent Distributed Technologies * Copyright (C) 2004 Bull SA * Copyright (C) 1996 - 2000 Dyade * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Initial developer(s): Frederic Maistre (INRIA) * Contributor(s): ScalAgent Distributed Technologies */package org.objectweb.joram.client.jms;import java.net.ConnectException;import java.util.Enumeration;import java.util.Hashtable;import java.util.List;import java.util.ListIterator;import java.util.Properties;import java.util.Vector;import javax.naming.*;import org.objectweb.util.monolog.api.BasicLevel;import org.objectweb.joram.client.jms.admin.DeadMQueue;import org.objectweb.joram.client.jms.admin.User;import org.objectweb.joram.client.jms.admin.AdministeredObject;import org.objectweb.joram.client.jms.admin.AdminModule;import org.objectweb.joram.client.jms.admin.AdminException;import org.objectweb.joram.client.jms.admin.XmlSerializer;import org.objectweb.joram.shared.admin.*;import fr.dyade.aaa.util.management.MXWrapper;/** * Implements the <code>javax.jms.Destination</code> interface and provides * JORAM specific administration and monitoring methods. */public abstract class Destination extends AdministeredObject implements javax.jms.Destination, DestinationMBean { /** Identifier of the agent destination. */ protected String agentId; /** Name given by the administrator. */ protected String adminName; private String type; // Used by jndi2 SoapObjectHelper public Destination() {} protected Destination(String name, String type) { agentId = name; this.type = type; } /** Returns the name of the destination. */ public String getName() { return agentId; } /** Returns the admin name of the destination. */ public final String getAdminName() { return adminName; } public final String getType() { return type; } /** * Returns <code>true</code> if the parameter object is a Joram destination * wrapping the same agent identifier. */ public boolean equals(Object obj) { if (! (obj instanceof Destination)) return false; return (getName().equals(((Destination) obj).getName())); } /** * Returns a String image of the queue. * * @return A provider-specific identity values for this queue. */ public String toString() { StringBuffer strbuf = new StringBuffer(); strbuf.append(type).append(agentId); if (adminName != null) strbuf.append('(').append(adminName).append(')'); return strbuf.toString(); } /** * Format the destination properties in a XML format * @param indent use this indent for prexifing XML representation. * @param serverId server id hosting the destination object * @return returns a XML view of the queue (admin format) * @throws ConnectException if the server is unreachable * @throws AdminException if an error occurs */ public String toXml(int indent, int serverId) throws ConnectException, AdminException { StringBuffer strbuf = new StringBuffer(); strbuf.append(XmlSerializer.indent(indent)); if (getType().equals("queue")) { strbuf.append("<Queue "); } else if (getType().equals("topic")) { strbuf.append("<Topic "); } else { return ""; } strbuf.append(XmlSerializer.xmlAttribute(getAdminName(), "name")); strbuf.append(XmlSerializer.xmlAttribute(String.valueOf(serverId), "serverId")); DeadMQueue dmq = getDMQ(); if (dmq != null) { strbuf.append(XmlSerializer.xmlAttribute(dmq.getAdminName(), "dmq")); strbuf.append(XmlSerializer.xmlAttribute(String.valueOf(dmq.getThreshold()), "threshold")); } strbuf.append(">\n"); indent+=2; if (isFreelyReadable()) { strbuf.append(XmlSerializer.indent(indent)); strbuf.append("<freeReader/>\n"); } if (isFreelyWriteable()) { strbuf.append(XmlSerializer.indent(indent)); strbuf.append("<freeWriter/>\n"); } strbuf.append(XmlSerializer.indent(indent)); strbuf.append("<jndi "); strbuf.append(XmlSerializer.xmlAttribute(getAdminName(), "name")); strbuf.append("/>\n"); indent-=2; strbuf.append(XmlSerializer.indent(indent)); if (getType().equals("queue")) { strbuf.append("</Queue>\n"); } else if (getType().equals("topic")) { strbuf.append("</Topic>\n"); } return strbuf.toString(); } /** * Returns <code>true</code> if the destination is a queue. */ public boolean isQueue() { return (this instanceof Queue); } /** * Codes a <code>Destination</code> as a Hashtable for travelling through the * SOAP protocol. */ public Hashtable code() { Hashtable h = new Hashtable(); h.put("agentId", getName()); h.put("type", type); return h; } public void decode(Hashtable h) { agentId = (String) h.get("agentId"); type = (String) h.get("type"); } /** Sets the naming reference of a destination. */ public Reference getReference() throws NamingException { Reference ref = super.getReference(); ref.add(new StringRefAddr("dest.name", getName())); return ref; } /** * Admin method creating or retrieving a destination with a given name on a * given server, and returning its identifier. * <p> * The request fails if the target server does not belong to the platform, * or if the destination deployement fails server side. * * @param serverId The identifier of the server where deploying the * destination. * @param name The destination name. * @param className Name of the MOM destination class. * @param prop Properties. * * @exception ConnectException If the admin connection is closed or broken. * @exception AdminException If the request fails. */ protected static void doCreate( int serverId, String name, String className, Properties props, Destination dest, String expectedType) throws ConnectException, AdminException { if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) JoramTracing.dbgClient.log( BasicLevel.DEBUG, "Destination.doCreate(" + serverId + ',' + name + ',' + className + ',' + props + ',' + dest + ',' + expectedType + ')'); CreateDestinationRequest cdr = new CreateDestinationRequest(serverId, name, className, props, expectedType); CreateDestinationReply reply = (CreateDestinationReply) AdminModule.doRequest(cdr); dest.agentId = reply.getId(); dest.adminName = name; dest.type = reply.getType(); } /** * Admin method removing this destination from the platform. * * @exception AdminException Never thrown. * @exception ConnectException If the admin connection is closed or broken. * @exception JMSException Never thrown. */ public void delete() throws ConnectException, AdminException, javax.jms.JMSException { AdminModule.doRequest(new DeleteDestination(getName())); if (MXWrapper.mxserver != null) { StringBuffer buff = new StringBuffer(); buff.append("type="); buff.append(getType()); buff.append(",name="); buff.append(getAdminName()); try { MXWrapper.unregisterMBean("joramClient",buff.toString()); } catch (Exception e) { if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) JoramTracing.dbgClient.log(BasicLevel.DEBUG, "unregisterMBean",e); } } } /** * Admin method setting free reading access to this destination. * <p> * The request fails if this destination is deleted server side. * * @exception ConnectException If the admin connection is closed or broken. * @exception AdminException If the request fails. */ public void setFreeReading() throws ConnectException, AdminException { AdminModule.doRequest(new SetReader(null, getName())); } /** * Admin method setting free writing access to this destination. * <p> * The request fails if this destination is deleted server side. * * @exception ConnectException If the admin connection is closed or broken. * @exception AdminException If the request fails. */ public void setFreeWriting() throws ConnectException, AdminException { AdminModule.doRequest(new SetWriter(null, getName())); } /** * Admin method unsetting free reading access to this destination. * <p> * The request fails if this destination is deleted server side. * * @exception ConnectException If the admin connection is closed or broken. * @exception AdminException If the request fails. */ public void unsetFreeReading() throws ConnectException, AdminException { AdminModule.doRequest(new UnsetReader(null, getName())); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -