/* * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package connector; import java.util.*; import javax.resource.NotSupportedException; import javax.resource.ResourceException; import javax.resource.spi.ActivationSpec; import javax.resource.spi.TransactionSupport.TransactionSupportLevel; import javax.resource.spi.endpoint.MessageEndpointFactory; import javax.resource.spi.*; import javax.resource.spi.work.Work; import javax.resource.spi.work.WorkManager; import javax.transaction.xa.XAResource; /** * This is a sample resource adapter * * @author Qingqing Ouyang */ @Connector( /* moduleName="My Simple RAR", */ displayName = "Simple Resource Adapter", vendorName = "Java Software", eisType = "Generic Type", version = "1.0Alpha", transactionSupport=TransactionSupportLevel.XATransaction) public class SimpleResourceAdapterImpl extends AbstractResourceAdapter implements ResourceAdapter, java.io.Serializable { private static final long serialVersionUID = -8470883868587583959L; private BootstrapContext ctx; private WorkManager wm; private Work work; public SimpleResourceAdapterImpl() { debug("constructor..."); } public void start(BootstrapContext ctx) throws ResourceAdapterInternalException { debug("001. Simple RA start..."); this.ctx = ctx; debug("002. Simple RA start..."); this.wm = ctx.getWorkManager(); debug("003. Simple RA start..."); // testing creat timer Timer timer = null; try { timer = ctx.createTimer(); } catch (UnavailableException ue) { System.out.println("Error"); throw new ResourceAdapterInternalException("Error form bootstrap"); } debug("004. Simple RA start..."); } public void stop() { debug("999. Simple RA stop..."); if (work != null) { ((WorkDispatcher) work).stop(); synchronized (Controls.readyLock) { Controls.readyLock.notify(); } } } public void endpointActivation(MessageEndpointFactory factory, ActivationSpec spec) throws NotSupportedException { try { debug("B.000. Create and schedule Dispatcher"); spec.validate(); work = new WorkDispatcher("DISPATCHER", ctx, factory, spec); wm.scheduleWork(work, 4 * 1000, null, null); debug("B.001. Scheduled Dispatcher"); } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } } public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) { debug("endpointDeactivation called..."); ((WorkDispatcher) work).stop(); } public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException { throw new UnsupportedOperationException(); } }