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.resource.adapter.jms;
023:
024: import java.util.Iterator;
025: import java.util.Map;
026:
027: import javax.resource.ResourceException;
028: import javax.resource.spi.ActivationSpec;
029: import javax.resource.spi.BootstrapContext;
030: import javax.resource.spi.ResourceAdapter;
031: import javax.resource.spi.ResourceAdapterInternalException;
032: import javax.resource.spi.endpoint.MessageEndpointFactory;
033: import javax.resource.spi.work.WorkManager;
034: import javax.transaction.xa.XAResource;
035:
036: import org.jboss.logging.Logger;
037: import org.jboss.resource.adapter.jms.inflow.JmsActivation;
038: import org.jboss.resource.adapter.jms.inflow.JmsActivationSpec;
039:
040: import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
041:
042: /**
043: * A generic resource adapter for any JMS server.
044: *
045: * @author <a href="adrian@jboss.com">Adrian Brock</a>
046: * @version $Revision: 57189 $
047: */
048: public class JmsResourceAdapter implements ResourceAdapter {
049: /** The logger */
050: private static final Logger log = Logger
051: .getLogger(JmsResourceAdapter.class);
052:
053: /** The bootstrap context */
054: private BootstrapContext ctx;
055:
056: /** The activations by activation spec */
057: private ConcurrentReaderHashMap activations = new ConcurrentReaderHashMap();
058:
059: /**
060: * Get the work manager
061: *
062: * @return the work manager
063: */
064: public WorkManager getWorkManager() {
065: return ctx.getWorkManager();
066: }
067:
068: public void endpointActivation(
069: MessageEndpointFactory endpointFactory, ActivationSpec spec)
070: throws ResourceException {
071: JmsActivation activation = new JmsActivation(this ,
072: endpointFactory, (JmsActivationSpec) spec);
073: activations.put(spec, activation);
074: activation.start();
075: }
076:
077: public void endpointDeactivation(
078: MessageEndpointFactory endpointFactory, ActivationSpec spec) {
079: JmsActivation activation = (JmsActivation) activations
080: .remove(spec);
081: if (activation != null)
082: activation.stop();
083: }
084:
085: public XAResource[] getXAResources(ActivationSpec[] specs)
086: throws ResourceException {
087: // TODO getXAResources
088: return null;
089: }
090:
091: public void start(BootstrapContext ctx)
092: throws ResourceAdapterInternalException {
093: this .ctx = ctx;
094: }
095:
096: public void stop() {
097: for (Iterator i = activations.entrySet().iterator(); i
098: .hasNext();) {
099: Map.Entry entry = (Map.Entry) i.next();
100: try {
101: JmsActivation activation = (JmsActivation) entry
102: .getValue();
103: if (activation != null)
104: activation.stop();
105: } catch (Exception ignored) {
106: log.debug("Ignored", ignored);
107: }
108: i.remove();
109: }
110: }
111: }
|