001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mq.il.jvm;
023:
024: import java.util.Properties;
025:
026: import javax.naming.InitialContext;
027:
028: import org.jboss.mq.GenericConnectionFactory;
029: import org.jboss.mq.il.ServerIL;
030: import org.jboss.mq.il.ServerILFactory;
031: import org.jboss.util.naming.NonSerializableFactory;
032:
033: /**
034: * Implements the ServerILJMXService which is used to manage the JVM IL.
035: *
036: * @author Hiram Chirino (Cojonudo14@hotmail.com)
037: * @author David Maplesden (David.Maplesden@orion.co.nz)
038: * @created August 16, 2001
039: * @version $Revision: 60196 $
040: *
041: * @jmx:mbean extends="org.jboss.mq.il.ServerILJMXServiceMBean"
042: */
043: public class JVMServerILService extends
044: org.jboss.mq.il.ServerILJMXService implements
045: JVMServerILServiceMBean {
046:
047: /**
048: * Gives this JMX service a name.
049: *
050: * @return The Name value
051: */
052: public String getName() {
053: return "JBossMQ-JVMServerIL";
054: }
055:
056: /**
057: * Used to construct the GenericConnectionFactory (bindJNDIReferences()
058: * builds it)
059: *
060: * @return The ServerIL value
061: * @returns ServerIL the instance of this IL
062: */
063: public ServerIL getServerIL() {
064: return new JVMServerIL(getJMSServer());
065: }
066:
067: /**
068: * Used to construct the GenericConnectionFactory (bindJNDIReferences()
069: * builds it) Sets up the connection properties need by a client to use this
070: * IL
071: *
072: * @return The ClientConnectionProperties value
073: */
074: public java.util.Properties getClientConnectionProperties() {
075: Properties rc = super .getClientConnectionProperties();
076: rc.setProperty(ServerILFactory.CLIENT_IL_SERVICE_KEY,
077: "org.jboss.mq.il.jvm.JVMClientILService");
078: rc.setProperty(ServerILFactory.SERVER_IL_FACTORY_KEY,
079: "org.jboss.mq.il.jvm.JVMServerILFactory");
080: return rc;
081: }
082:
083: /**
084: * Starts this IL, and binds it to JNDI
085: *
086: * @exception Exception Description of Exception
087: */
088: public void startService() throws Exception {
089: super .startService();
090: bindJNDIReferences();
091: }
092:
093: /**
094: * Stops this IL, and unbinds it from JNDI
095: */
096: public void stopService() {
097: try {
098: unbindJNDIReferences();
099: } catch (Exception e) {
100: log.error("Problem stopping JVMServerILService", e);
101: }
102: }
103:
104: /**
105: * Binds the connection factories for this IL
106: *
107: * @throws javax.naming.NamingException it cannot be unbound
108: */
109: public void bindJNDIReferences()
110: throws javax.naming.NamingException {
111:
112: GenericConnectionFactory gcf = new GenericConnectionFactory(
113: getServerIL(), getClientConnectionProperties());
114: org.jboss.mq.SpyConnectionFactory scf = new org.jboss.mq.SpyConnectionFactory(
115: gcf);
116: org.jboss.mq.SpyXAConnectionFactory sxacf = new org.jboss.mq.SpyXAConnectionFactory(
117: gcf);
118:
119: // Get an InitialContext
120: InitialContext ctx = getInitialContext();
121: NonSerializableFactory.rebind(ctx,
122: getConnectionFactoryJNDIRef(), scf);
123: NonSerializableFactory.rebind(ctx,
124: getXAConnectionFactoryJNDIRef(), sxacf);
125:
126: }
127: }
|