KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > connector > JoramAdapter


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - 2007 ScalAgent Distributed Technologies
4  * Copyright (C) 2004 - 2006 Bull SA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (Bull SA)
22  * Contributor(s): ScalAgent Distributed Technologies
23  * Benoit Pelletier (Bull SA)
24  */

25 package org.objectweb.joram.client.connector;
26
27 import fr.dyade.aaa.agent.AgentServer;
28 import com.scalagent.jmx.JMXServer;
29 import org.objectweb.joram.client.jms.Queue;
30 import org.objectweb.joram.client.jms.Topic;
31 import org.objectweb.joram.client.jms.admin.AdminException;
32 import org.objectweb.joram.client.jms.admin.JoramAdmin;
33 import org.objectweb.joram.client.jms.admin.User;
34 import org.objectweb.joram.client.jms.admin.DeadMQueue;
35 import org.objectweb.joram.client.jms.ha.local.XAHALocalConnectionFactory;
36 import org.objectweb.joram.client.jms.ha.tcp.XAHATcpConnectionFactory;
37 import org.objectweb.joram.client.jms.ha.local.TopicHALocalConnectionFactory;
38 import org.objectweb.joram.client.jms.ha.tcp.TopicHATcpConnectionFactory;
39
40 import org.objectweb.joram.client.jms.local.TopicLocalConnectionFactory;
41 import org.objectweb.joram.client.jms.local.XALocalConnectionFactory;
42 import org.objectweb.joram.client.jms.tcp.TopicTcpConnectionFactory;
43 import org.objectweb.joram.client.jms.tcp.XATcpConnectionFactory;
44 import org.objectweb.joram.client.jms.ConnectionMetaData;
45
46 import java.io.BufferedReader JavaDoc;
47 import java.io.File JavaDoc;
48 import java.io.FileReader JavaDoc;
49 import java.io.IOException JavaDoc;
50 import java.lang.reflect.Method JavaDoc;
51 import java.net.ConnectException JavaDoc;
52 import java.util.Enumeration JavaDoc;
53 import java.util.Hashtable JavaDoc;
54 import java.util.List JavaDoc;
55 import java.util.Properties JavaDoc;
56 import java.util.StringTokenizer JavaDoc;
57 import java.util.Vector JavaDoc;
58
59 import javax.jms.Destination JavaDoc;
60 import javax.jms.Session JavaDoc;
61 import javax.jms.TopicConnectionFactory JavaDoc;
62 import javax.jms.XAConnection JavaDoc;
63 import javax.jms.XAConnectionFactory JavaDoc;
64 import javax.management.MBeanServer JavaDoc;
65 import javax.management.MBeanServerFactory JavaDoc;
66 import javax.management.ObjectName JavaDoc;
67 import javax.naming.Context JavaDoc;
68 import javax.naming.InitialContext JavaDoc;
69 import javax.resource.NotSupportedException JavaDoc;
70 import javax.resource.ResourceException JavaDoc;
71 import javax.resource.spi.ActivationSpec JavaDoc;
72 import javax.resource.spi.BootstrapContext JavaDoc;
73 import javax.resource.spi.CommException JavaDoc;
74 import javax.resource.spi.IllegalStateException JavaDoc;
75 import javax.resource.spi.ResourceAdapterInternalException JavaDoc;
76 import javax.resource.spi.endpoint.MessageEndpointFactory JavaDoc;
77 import javax.resource.spi.work.WorkManager JavaDoc;
78 import javax.transaction.xa.XAResource JavaDoc;
79
80 import org.objectweb.util.monolog.api.BasicLevel;
81
82 /**
83  * A <code>JoramAdapter</code> instance manages connectivities to an
84  * underlying JORAM server: outbound connectivity (JCA connection
85  * management contract) and inbound connectivity (asynchronous message
86  * delivery as specified by the JCA message inflow contract).
87  */

88 public class JoramAdapter
89   implements javax.resource.spi.ResourceAdapter JavaDoc,
90              java.io.Serializable JavaDoc, JoramAdapterMBean {
91   /** <code>WorkManager</code> instance provided by the application server. */
92   private transient WorkManager JavaDoc workManager;
93
94   /**
95    * Table holding the adapter's <code>InboundConsumer</code> instances,
96    * for inbound messaging.
97    * <p>
98    * <b>Key:</b> <code>ActivationSpec</code> instance<br>
99    * <b>Value:</b> <code>InboundConsumer</code> instance
100    */

101   private transient Hashtable JavaDoc consumers;
102   /**
103    * Vector holding the <code>ManagedConnectionImpl</code> instances for
104    * managed outbound messaging.
105    */

106   private transient Vector JavaDoc producers;
107   /**
108    * Table holding the adapter's <code>XAConnection</code> instances used for
109    * recovering the XA resources.
110    * <p>
111    * <b>Key:</b> user name<br>
112    * <b>Value:</b> <code>XAConnection</code> instance
113    */

114   private transient Hashtable JavaDoc connections;
115
116   /** <code>true</code> if the adapter has been started. */
117   private boolean started = false;
118   /** <code>true</code> if the adapter has been stopped. */
119   private boolean stopped = false;
120
121   /** <code>true</code> if the underlying JORAM server is collocated. */
122   boolean collocated = false;
123
124   /** <code>true</code> if the underlying a JORAM HA server is defined */
125   boolean isHa = false;
126
127   /** Host name or IP of the underlying JORAM server. */
128   String JavaDoc hostName = "localhost";
129   /** Port number of the underlying JORAM server. */
130   int serverPort = 16010;
131
132   /** Identifier of the JORAM server to start. */
133   short serverId = 0;
134
135   /** Identifier of the JORAM replica to start in case of HA. */
136   short clusterId = AgentServer.NULL_ID;
137
138   /** Platform servers identifiers. */
139   List JavaDoc platformServersIds = null;
140
141   /**
142    * Path to the directory containing JORAM's configuration files
143    * (<code>a3servers.xml</code>, <code>a3debug.cfg</code>
144    * and admin file), needed when starting the collocated JORAM server.
145    */

146   private String JavaDoc platformConfigDir;
147   /** <code>true</code> if the JORAM server to start is persistent. */
148   private boolean persistentPlatform = false;
149   /**
150    * Path to the file containing a description of the administered objects to
151    * create and bind.
152    */

153   private String JavaDoc adminFile = "joram-admin.cfg";
154   private String JavaDoc adminFileXML = "joramAdmin.xml";
155
156
157   /**
158    * Path to the file containing a description of the exported administered objects (destination)
159    */

160   private String JavaDoc adminFileExportXML = "joramAdminExport.xml";
161
162   /** Name of the JORAM server to start. */
163   private String JavaDoc serverName = "s0";
164
165   /** Names of the bound objects. */
166   private static Vector JavaDoc boundNames = new Vector JavaDoc();
167   /** Standard JMSResource MBean ObjectName. */
168   private static ObjectName JavaDoc jmsResourceON;
169   /** Local MBean server. */
170   private static MBeanServer JavaDoc mbs = null;
171
172   /**
173    * Duration in seconds during which connecting is attempted (connecting
174    * might take time if the server is temporarily not reachable); the 0 value
175    * is set for connecting only once and aborting if connecting failed.
176    */

177   public int connectingTimer = 0;
178   /**
179    * Duration in seconds during which a JMS transacted (non XA) session might
180    * be pending; above that duration the session is rolled back and closed;
181    * the 0 value means "no timer".
182    */

183   public int txPendingTimer = 0;
184   /**
185    * Period in milliseconds between two ping requests sent by the client
186    * connection to the server; if the server does not receive any ping
187    * request during more than 2 * cnxPendingTimer, the connection is
188    * considered as dead and processed as required.
189    */

190   public int cnxPendingTimer = 0;
191
192   /**
193    * The maximum number of messages that can be
194    * read at once from a queue.
195    *
196    * Default value is 2 in order to compensate
197    * the former subscription mechanism.
198    */

199   public int queueMessageReadMax = 2;
200
201   /**
202    * The maximum number of acknowledgements
203    * that can be buffered in
204    * Session.DUPS_OK_ACKNOWLEDGE mode when listening to a topic.
205    * Default is 0.
206    */

207   public int topicAckBufferMax = 0;
208
209   /**
210    * This threshold is the maximum messages
211    * number over
212    * which the subscription is passivated.
213    * Default is Integer.MAX_VALUE.
214    */

215   public int topicPassivationThreshold = Integer.MAX_VALUE;
216
217   /**
218    * This threshold is the minimum
219    * messages number below which
220    * the subscription is activated.
221    * Default is 0.
222    */

223   public int topicActivationThreshold = 0;
224
225   /**
226    * Determines whether the produced messages are asynchronously
227    * sent or not (without or with acknowledgement)
228    * Default is false (with ack).
229    */

230   public boolean asyncSend = false;
231
232   /**
233    * Determines whether client threads
234    * which are using the same connection
235    * are synchronized in order to group
236    * together the requests they send.
237    * Default is false.
238    */

239   public boolean multiThreadSync = false;
240
241   /**
242    * The maximum time the threads hang if 'multiThreadSync' is true.
243    * Either they wake up (wait time out) or they are notified (by the
244    * first woken up thread).
245    *
246    * Default is 1 ms.
247    */

248   public int multiThreadSyncDelay = 1;
249
250   /**
251    * Determine whether durablesubscription must be deleted or not
252    * at close time of the InboundConsumer.
253    * Default is false.
254    */

255   public boolean deleteDurableSubscription = false;
256
257   public JMXServer jmxServer;
258
259   private transient JoramAdmin joramAdmin;
260
261   /**
262    * Constructs a <code>JoramAdapter</code> instance.
263    */

264   public JoramAdapter() {
265     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
266       AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
267                                     "JORAM adapter instantiated.");
268
269     consumers = new Hashtable JavaDoc();
270     producers = new Vector JavaDoc();
271
272     java.util.ArrayList JavaDoc array = MBeanServerFactory.findMBeanServer(null);
273     if (!array.isEmpty())
274       mbs = (MBeanServer JavaDoc) array.get(0);
275     jmxServer = new JMXServer(mbs,"JoramAdapter");
276   }
277
278   /**
279    * Initializes the adapter; starts, if needed, a collocated JORAM server,
280    * and if needed again, administers it.
281    *
282    * @exception ResourceAdapterInternalException If the adapter could not be
283    * initialized.
284    */

285   public synchronized void start(BootstrapContext JavaDoc ctx)
286                            throws ResourceAdapterInternalException JavaDoc
287   {
288       // set HA mode if needed
289
joramAdmin.setHa(isHa);
290
291     if (started)
292       throw new ResourceAdapterInternalException JavaDoc("Adapter already started.");
293     if (stopped)
294       throw new ResourceAdapterInternalException JavaDoc("Adapter has been stopped.");
295
296     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
297       AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
298                                     "JORAM adapter starting deployment...");
299
300     workManager = ctx.getWorkManager();
301
302     // Collocated mode: starting the JORAM server.
303
if (collocated) {
304       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
305         AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
306                                       " - Collocated JORAM server is starting...");
307
308       if (persistentPlatform) {
309         System.setProperty("Transaction", "fr.dyade.aaa.util.NTransaction");
310         System.setProperty("NTNoLockFile", "true");
311       } else {
312         System.setProperty("Transaction", "fr.dyade.aaa.util.NullTransaction");
313         System.setProperty("NbMaxAgents", "" + Integer.MAX_VALUE);
314       }
315
316       if (platformConfigDir != null) {
317         System.setProperty("fr.dyade.aaa.agent.A3CONF_DIR", platformConfigDir);
318         System.setProperty("fr.dyade.aaa.DEBUG_DIR", platformConfigDir);
319       }
320
321       try {
322         AgentServer.init(serverId, serverName, null, clusterId);
323         AgentServer.start();
324         if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
325           AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
326                                         " - Collocated JORAM server has successfully started.");
327       } catch (Exception JavaDoc exc) {
328         AgentServer.stop();
329         AgentServer.reset(true);
330
331         throw new ResourceAdapterInternalException JavaDoc("Could not start "
332                                                    + "collocated JORAM "
333                                                    + " instance: " + exc);
334       }
335     }
336
337     // Starting admin.
338
try {
339       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
340         AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
341                                       " - Reading the provided admin file: " + adminFileXML);
342       JoramAdmin.executeXMLAdmin(platformConfigDir, adminFileXML);
343     } catch (Exception JavaDoc exc) {
344       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
345         AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
346                                       "JORAM ADMIN XML not found.");
347     }
348
349     // Starting an admin session...
350
try {
351       adminConnect();
352       serverId = (short) joramAdmin.getPlatformAdmin().getLocalServerId();
353     } catch (Exception JavaDoc exc) {
354       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.WARN))
355         AdapterTracing.dbgAdapter.log(BasicLevel.WARN,
356                                       " - JORAM server not administerable: " + exc);
357     }
358
359     // Recreates the objects (backup) if the export file is present
360
if (joramAdmin != null) {
361         joramAdmin.setAdminFileExportXML(adminFileExportXML);
362
363         try {
364             if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
365                 AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
366                                       " - Reading the provided admin file: " + adminFileExportXML);
367             JoramAdmin.executeXMLAdmin(platformConfigDir, adminFileExportXML);
368
369             // redo the admin connection as the executeXMLAdmin has closed the session
370
adminConnect();
371         } catch (Exception JavaDoc exc) {
372             if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
373                 AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
374                         adminFileExportXML + " not found.");
375         }
376     }
377
378     // Administering as specified in the properties file.
379
try {
380       File JavaDoc file = null;
381
382       try {
383         if (platformConfigDir == null) {
384           java.net.URL JavaDoc url = ClassLoader.getSystemResource(adminFile);
385           file = new File JavaDoc(url.getFile());
386         }
387         else
388           file = new File JavaDoc(platformConfigDir, adminFile);
389       } catch (NullPointerException JavaDoc e) {
390         throw new java.io.FileNotFoundException JavaDoc();
391       }
392
393       FileReader JavaDoc fileReader = new FileReader JavaDoc(file);
394       BufferedReader JavaDoc reader = new BufferedReader JavaDoc(fileReader);
395
396       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
397         AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
398                                       " - Reading the provided admin file: " + file);
399
400       boolean end = false;
401       String JavaDoc line;
402       StringTokenizer JavaDoc tokenizer;
403       String JavaDoc firstToken;
404       String JavaDoc name = null;
405
406       while (! end) {
407         try {
408           line = reader.readLine();
409
410           if (line == null)
411             end = true;
412           else {
413             tokenizer = new StringTokenizer JavaDoc(line);
414
415             if (tokenizer.hasMoreTokens()) {
416               firstToken = tokenizer.nextToken();
417               if (firstToken.equalsIgnoreCase("Host")) {
418                 if (tokenizer.hasMoreTokens())
419                   hostName = tokenizer.nextToken();
420               }
421               else if (firstToken.equalsIgnoreCase("Port")) {
422                 if (tokenizer.hasMoreTokens())
423                   serverPort = Integer.parseInt(tokenizer.nextToken());
424               }
425               else if (firstToken.equalsIgnoreCase("Queue")) {
426                 if (tokenizer.hasMoreTokens()) {
427                   name = tokenizer.nextToken();
428                   createQueue(name);
429                 }
430               }
431               else if (firstToken.equalsIgnoreCase("Topic")) {
432                 if (tokenizer.hasMoreTokens()) {
433                   name = tokenizer.nextToken();
434                   createTopic(name);
435                 }
436               }
437               else if (firstToken.equalsIgnoreCase("User")) {
438                 if (tokenizer.hasMoreTokens())
439                   name = tokenizer.nextToken();
440                 if (tokenizer.hasMoreTokens()) {
441                   String JavaDoc password = tokenizer.nextToken();
442                   createUser(name, password);
443                 }
444                 else
445                   if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
446                     AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
447                                                   " - Missing password for user [" + name + "]");
448               }
449               else if (firstToken.equalsIgnoreCase("CF")) {
450                 if (tokenizer.hasMoreTokens()) {
451                   name = tokenizer.nextToken();
452                   createCF(name);
453                 }
454               }
455               else if (firstToken.equalsIgnoreCase("QCF")) {
456                 if (tokenizer.hasMoreTokens()) {
457                   name = tokenizer.nextToken();
458                   createQCF(name);
459                 }
460               }
461               else if (firstToken.equalsIgnoreCase("TCF")) {
462                 if (tokenizer.hasMoreTokens()) {
463                   name = tokenizer.nextToken();
464                   createTCF(name);
465                 }
466               }
467             }
468           }
469         }
470         // Error while reading one line.
471
catch (IOException JavaDoc exc) {
472         // Error while creating the destination.
473
} catch (AdminException exc) {
474           AdapterTracing.dbgAdapter.log(BasicLevel.ERROR,
475                                         "Creation failed",exc);
476         }
477       }
478     }
479     // No destination to deploy.
480
catch (java.io.FileNotFoundException JavaDoc fnfe) {
481       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
482         AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
483                                       " - No administration task requested.");
484     }
485
486     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
487       AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
488                                     "Server port is " + serverPort);
489
490     started = true;
491
492     // Registering MBeans...
493
try {
494       jmxServer.registerMBean(this,
495                               "joramClient",
496                               "type=JoramAdapter,version=" +
497                               ConnectionMetaData.providerVersion);
498     } catch (Exception JavaDoc e) {
499       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.WARN))
500         AdapterTracing.dbgAdapter.log(BasicLevel.WARN,
501                                       " - Could not register JoramAdapterMBean",
502                                       e);
503     }
504
505     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
506       AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
507                                     "JORAM adapter " +
508                                     ConnectionMetaData.providerVersion +
509                                     " successfully deployed.");
510   }
511
512   /**
513    * Notifies the adapter to terminate the connections it manages, and if
514    * needed, to shut down the collocated JORAM server.
515    */

516   public synchronized void stop()
517   {
518     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
519       AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
520                                     "JORAM adapter stopping...");
521
522     if (! started || stopped)
523       return;
524
525     // Unbinds the bound objects...
526
while (! boundNames.isEmpty())
527       unbind((String JavaDoc) boundNames.remove(0));
528
529     // Finishing the admin session.
530
joramAdmin.getPlatformAdmin().disconnect();
531
532     // Closing the outbound connections, if any.
533
while (! producers.isEmpty()) {
534       try {
535         ((ManagedConnectionImpl) producers.remove(0)).destroy();
536       }
537       catch (Exception JavaDoc exc) {}
538     }
539
540     // Closing the inbound connections, if any.
541
for (Enumeration JavaDoc keys = consumers.keys(); keys.hasMoreElements();)
542       ((InboundConsumer) consumers.get(keys.nextElement())).close();
543
544     // Browsing the recovery connections, if any.
545
if (connections != null) {
546       for (Enumeration JavaDoc keys = connections.keys(); keys.hasMoreElements();) {
547         try {
548           ((XAConnection JavaDoc) connections.get(keys.nextElement())).close();
549         }
550         catch (Exception JavaDoc exc) {}
551       }
552     }
553
554     // If JORAM server is collocated, stopping it.
555
if (collocated) {
556       try {
557         AgentServer.stop();
558       }
559       catch (Exception JavaDoc exc) {}
560     }
561
562     stopped = true;
563
564     try {
565       jmxServer.unregisterMBean("joramClient",
566                                 "type=JoramAdapter,version=" +
567                                 ConnectionMetaData.providerVersion);
568     } catch (Exception JavaDoc e) {
569       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.WARN))
570         AdapterTracing.dbgAdapter.log(BasicLevel.WARN,
571                                       "unregisterMBean",
572                                       e);
573     }
574
575
576     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
577       AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
578                                     "JORAM adapter successfully stopped.");
579   }
580
581   /**
582    * Notifies the adapter to setup asynchronous message delivery for an
583    * application server endoint.
584    *
585    * @exception IllegalStateException If the adapter is either not started,
586    * or stopped.
587    * @exception NotSupportedException If the provided activation parameters
588    * are invalid.
589    * @exception CommException If the JORAM server is not reachable.
590    * @exception SecurityException If connecting is not allowed.
591    * @exception ResourceException Generic exception.
592    */

593   public void endpointActivation(MessageEndpointFactory JavaDoc endpointFactory,
594                                  ActivationSpec JavaDoc spec)
595               throws ResourceException JavaDoc {
596     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
597       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
598                                     this + " endpointActivation(" + endpointFactory +
599                                     ", " + spec + ")");
600
601     if (! started)
602       throw new IllegalStateException JavaDoc("Non started resource adapter.");
603     if (stopped)
604       throw new IllegalStateException JavaDoc("Stopped resource adapter.");
605
606     if (! (spec instanceof ActivationSpecImpl))
607       throw new ResourceException JavaDoc("Provided ActivationSpec instance is not "
608                                   + "a JORAM activation spec.");
609
610     ActivationSpecImpl specImpl = (ActivationSpecImpl) spec;
611
612     if (! specImpl.getResourceAdapter().equals(this))
613       throw new ResourceException JavaDoc("Supplied ActivationSpec instance "
614                                   + "associated to an other ResourceAdapter.");
615
616     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
617       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
618                                     "Activating Endpoint on JORAM adapter.");
619
620     boolean durable =
621       specImpl.getSubscriptionDurability() != null
622       && specImpl.getSubscriptionDurability().equalsIgnoreCase("Durable");
623
624     boolean transacted = false;
625     try {
626       Class JavaDoc listenerClass = Class.forName("javax.jms.MessageListener");
627       Class JavaDoc[] parameters = { Class.forName("javax.jms.Message") };
628       Method JavaDoc meth = listenerClass.getMethod("onMessage", parameters);
629       transacted = endpointFactory.isDeliveryTransacted(meth);
630     }
631     catch (Exception JavaDoc exc) {
632       throw new ResourceException JavaDoc("Could not determine transactional "
633                                   + "context: " + exc);
634     }
635
636     int maxWorks = 10;
637     try {
638       maxWorks = Integer.parseInt(specImpl.getMaxNumberOfWorks());
639     } catch (Exception JavaDoc exc) {
640       throw new ResourceException JavaDoc("Invalid max number of works instances "
641                                   + "number: " + exc);
642     }
643
644     int maxMessages = 10;
645     try {
646       maxMessages = Integer.parseInt(specImpl.getMaxMessages());
647     } catch (Exception JavaDoc exc) {
648       throw new ResourceException JavaDoc("Invalid max messages "
649                                   + "number: " + exc);
650     }
651
652     int ackMode;
653     try {
654       if (ActivationSpecImpl.AUTO_ACKNOWLEDGE.equals(specImpl
655           .getAcknowledgeMode())) {
656         ackMode = Session.AUTO_ACKNOWLEDGE;
657       } else if (ActivationSpecImpl.AUTO_ACKNOWLEDGE.equals(specImpl
658           .getAcknowledgeMode())) {
659         ackMode = Session.DUPS_OK_ACKNOWLEDGE;
660       } else {
661         ackMode = Session.AUTO_ACKNOWLEDGE;
662       }
663     } catch (Exception JavaDoc exc) {
664       throw new ResourceException JavaDoc("Invalid acknowledge mode: " + exc);
665     }
666
667     String JavaDoc destType = specImpl.getDestinationType();
668     String JavaDoc destName = specImpl.getDestination();
669
670     try {
671       Destination JavaDoc dest;
672
673       if (destType.equals("javax.jms.Queue"))
674         dest = createQueue(destName);
675       else if (destType.equals("javax.jms.Topic"))
676         dest = createTopic(destName);
677       else
678         throw new NotSupportedException JavaDoc("Invalid destination type provided "
679                                         + "as activation parameter: "
680                                         + destType);
681
682       String JavaDoc userName = specImpl.getUserName();
683       String JavaDoc password = specImpl.getPassword();
684
685       createUser(userName, password);
686
687       XAConnectionFactory JavaDoc connectionFactory = null;
688
689       if (isHa) {
690           if (collocated)
691               connectionFactory = XAHALocalConnectionFactory.create();
692           else {
693               String JavaDoc urlHa = "hajoram://" + hostName + ":" + serverPort;
694               connectionFactory = XAHATcpConnectionFactory.create(urlHa);
695           }
696       } else {
697
698       if (collocated)
699         connectionFactory = XALocalConnectionFactory.create();
700       else
701               connectionFactory = XATcpConnectionFactory.create(hostName, serverPort);
702       }
703
704       ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory).getParameters().connectingTimer = connectingTimer;
705       ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory).getParameters().cnxPendingTimer = cnxPendingTimer;
706       ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory).getParameters().txPendingTimer = txPendingTimer;
707
708       if (queueMessageReadMax > 0) {
709         ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory)
710             .getParameters().queueMessageReadMax = queueMessageReadMax;
711       }
712
713       if (topicAckBufferMax > 0) {
714         ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory)
715             .getParameters().topicAckBufferMax = topicAckBufferMax;
716       }
717
718       if (topicPassivationThreshold > 0) {
719         ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory)
720             .getParameters().topicPassivationThreshold = topicPassivationThreshold;
721       }
722
723       if (topicActivationThreshold > 0) {
724         ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory)
725             .getParameters().topicActivationThreshold = topicActivationThreshold;
726       }
727
728       XAConnection JavaDoc cnx =
729         connectionFactory.createXAConnection(userName, password);
730
731       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
732         AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
733                                       this + " endpointActivation cnx = " + cnx);
734
735       // Creating and registering a consumer instance for this endpoint.
736
InboundConsumer consumer =
737         new InboundConsumer(workManager,
738                             endpointFactory,
739                             cnx,
740                             dest,
741                             specImpl.getMessageSelector(),
742                             durable,
743                             specImpl.getSubscriptionName(),
744                             transacted,
745                             maxWorks,
746                             maxMessages,
747                             ackMode,
748                             deleteDurableSubscription);
749
750       consumers.put(specImpl, consumer);
751     }
752     catch (javax.jms.JMSSecurityException JavaDoc exc) {
753       throw new SecurityException JavaDoc("Invalid user identification: " + exc);
754     }
755     catch (javax.jms.JMSException JavaDoc exc) {
756       throw new CommException JavaDoc("Could not connect to the JORAM server: "
757                               + exc);
758     }
759     catch (AdminException exc) {
760       throw new ResourceException JavaDoc("Problem when handling the JORAM "
761                                   + "destinations: " + exc);
762     }
763   }
764
765   /**
766    * Notifies the adapter to deactivate message delivery for a given endpoint.
767    */

768   public void endpointDeactivation(MessageEndpointFactory JavaDoc endpointFactory,
769                                    ActivationSpec JavaDoc spec) {
770     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
771       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
772                                     this + " endpointDeactivation(" + endpointFactory + ", " + spec + ")");
773     if (! started || stopped)
774       return;
775
776     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
777       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
778                                     "Deactivating Endpoint on JORAM adapter.");
779
780     ((InboundConsumer) consumers.remove(spec)).close();
781   }
782
783   /**
784    * Returns XA resources given an array of ActivationSpec instances.
785    *
786    * @exception IllegalStateException If the adapter is either not started,
787    * or stopped.
788    * @exception NotSupportedException If provided activation parameters
789    * are invalid.
790    * @exception CommException If the JORAM server is not reachable.
791    * @exception SecurityException If connecting is not allowed.
792    * @exception ResourceException Generic exception.
793    */

794   public XAResource JavaDoc[] getXAResources(ActivationSpec JavaDoc[] specs)
795     throws ResourceException JavaDoc {
796     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
797       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
798                                     this + " getXAResources(" + specs + ")");
799
800     if (! started)
801       throw new IllegalStateException JavaDoc("Non started resource adapter.");
802     if (stopped)
803       throw new IllegalStateException JavaDoc("Stopped resource adapter.");
804
805     ActivationSpecImpl specImpl;
806     String JavaDoc userName;
807     String JavaDoc password;
808     XAConnectionFactory JavaDoc connectionFactory = null;
809     XAConnection JavaDoc connection;
810     Vector JavaDoc resources = new Vector JavaDoc();
811
812     if (connections == null)
813       connections = new Hashtable JavaDoc();
814
815     try {
816       for (int i = 0; i < specs.length; i++) {
817         if (! (specs[i] instanceof ActivationSpecImpl))
818           throw new ResourceException JavaDoc("Provided ActivationSpec instance is "
819                                       + "not a JORAM activation spec.");
820
821         specImpl = (ActivationSpecImpl) specs[i];
822
823         if (! specImpl.getResourceAdapter().equals(this))
824           throw new ResourceException JavaDoc("Supplied ActivationSpec instance "
825                                       + "associated to an other "
826                                       + "ResourceAdapter.");
827
828         userName = specImpl.getUserName();
829
830         // The connection does not already exist: creating it.
831
if (! connections.containsKey(userName)) {
832           password = specImpl.getPassword();
833
834           if (isHa) {
835               if (collocated)
836                   connectionFactory = XAHALocalConnectionFactory.create();
837               else {
838                   String JavaDoc urlHa = "hajoram://" + hostName + ":" + serverPort;
839                   connectionFactory = XAHATcpConnectionFactory.create(urlHa);
840               }
841           } else {
842           if (collocated)
843             connectionFactory = XALocalConnectionFactory.create();
844           else
845                   connectionFactory = XATcpConnectionFactory.create(hostName, serverPort);
846           }
847
848           ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory).getParameters().connectingTimer = connectingTimer;
849           ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory).getParameters().cnxPendingTimer = cnxPendingTimer;
850           ((org.objectweb.joram.client.jms.XAConnectionFactory) connectionFactory).getParameters().txPendingTimer = txPendingTimer;
851
852           connection =
853             connectionFactory.createXAConnection(userName, password);
854
855           connections.put(userName, connection);
856
857           resources.add(connection.createXASession().getXAResource());
858         }
859         if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
860           AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
861                                         this + " getXAResources resources = " + resources);
862       }
863     }
864     catch (javax.jms.JMSSecurityException JavaDoc exc) {
865       throw new SecurityException JavaDoc("Invalid user identification: " + exc);
866     }
867     catch (javax.jms.JMSException JavaDoc exc) {
868       throw new CommException JavaDoc("Could not connect to the JORAM server: "
869                               + exc);
870     }
871
872     return (XAResource JavaDoc[]) resources.toArray(new XAResource JavaDoc[resources.size()]);
873   }
874
875
876   /** Returns a code depending on the adapter properties. */
877   public int hashCode()
878   {
879     return (collocated + " " + hostName + " " + serverPort).hashCode();
880   }
881
882   /** Compares adapters according to their properties. */
883   public boolean equals(Object JavaDoc o)
884   {
885     if (! (o instanceof JoramAdapter))
886       return false;
887
888     JoramAdapter other = (JoramAdapter) o;
889
890     boolean res =
891       collocated == other.collocated
892       && hostName.equals(other.hostName)
893       && serverPort == other.serverPort;
894
895     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
896       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
897                                     this + " equals = " + res);
898     return res;
899   }
900
901   public List JavaDoc getDestinations() {
902     return joramAdmin.getDestinations();
903   }
904
905   public List JavaDoc getDestinations(int serverId) {
906     return joramAdmin.getDestinations(serverId);
907   }
908
909   public List JavaDoc getUsers() {
910     return joramAdmin.getUsers();
911   }
912
913   public List JavaDoc getUsers(int serverId) {
914     return joramAdmin.getUsers(serverId);
915   }
916
917   public List JavaDoc getPlatformServersIds() {
918     return joramAdmin.getPlatformAdmin().getServersIds();
919   }
920
921   public List JavaDoc getLocalUsers() {
922     return joramAdmin.getUsers(serverId);
923   }
924
925   public void setDefaultDMQ(int serverId, DeadMQueue dmq)
926     throws ConnectException JavaDoc, AdminException {
927     joramAdmin.setDefaultDMQ(serverId,dmq);
928   }
929
930   public DeadMQueue getDefaultDMQ(int serverId)
931     throws ConnectException JavaDoc, AdminException {
932     return joramAdmin.getDefaultDMQ(serverId);
933   }
934
935   public DeadMQueue getDefaultDMQ()
936     throws ConnectException JavaDoc, AdminException {
937     return joramAdmin.getDefaultDMQ();
938   }
939
940   public void exit() {
941     joramAdmin.exit();
942   }
943
944   /**
945    * wait before abort a request.
946    */

947   public void setTimeOutToAbortRequest(long timeOut) {
948     joramAdmin.setTimeOutToAbortRequest(timeOut);
949   }
950
951   /**
952    * wait before abort a request.
953    */

954   public long getTimeOutToAbortRequest() {
955     return joramAdmin.getTimeOutToAbortRequest();
956   }
957
958   /**
959    * Creates or retrieves a user on the underlying JORAM server.
960    *
961    * @exception AdminException If the creation fails.
962    */

963   public void createUser(String JavaDoc name, String JavaDoc password)
964     throws AdminException {
965     try {
966       User.create(name, password);
967       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
968         AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
969                                       " - User [" + name + "] has been created.");
970     }
971     catch (ConnectException JavaDoc exc) {
972       throw new AdminException("createUser() failed: admin connection "
973                                + "has been lost.");
974     }
975   }
976
977   /**
978    * Creates or retrieves a user on the underlying JORAM server.
979    *
980    * @exception AdminException If the creation fails.
981    */

982   public void createUser(String JavaDoc name, String JavaDoc password, int serverId)
983     throws AdminException {
984     try {
985       User.create(name, password,serverId);
986       if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
987         AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
988                                       " - User [" + name + "] has been created.");
989     }
990     catch (ConnectException JavaDoc exc) {
991       throw new AdminException("createUser() failed: admin connection "
992                                + "has been lost.");
993     }
994   }
995
996   /**
997    * Creates a non managed connection factory and binds it to JNDI.
998    */

999   public void createCF(String JavaDoc name) {
1000    ManagedConnectionFactoryImpl mcf =
1001      new ManagedConnectionFactoryImpl();
1002
1003    try {
1004      mcf.setResourceAdapter(this);
1005      mcf.setCollocated(new Boolean JavaDoc(false));
1006
1007      Object JavaDoc factory = mcf.createConnectionFactory();
1008      bind(name, factory);
1009      if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
1010        AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
1011                                      " - ConnectionFactory [" + name
1012                                      + "] has been created and bound.");
1013    } catch (Exception JavaDoc exc) {}
1014  }
1015
1016  /**
1017   * Creates a non managed PTP connection factory and binds it to JNDI.
1018   */

1019  public void createQCF(String JavaDoc name) {
1020    ManagedConnectionFactoryImpl mcf =
1021      new ManagedQueueConnectionFactoryImpl();
1022
1023    try {
1024      mcf.setResourceAdapter(this);
1025      mcf.setCollocated(new Boolean JavaDoc(false));
1026
1027      Object JavaDoc factory = mcf.createConnectionFactory();
1028      bind(name, factory);
1029      if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
1030        AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
1031                                      " - QueueConnectionFactory [" + name
1032                                      + "] has been created and bound.");
1033    } catch (Exception JavaDoc exc) {}
1034  }
1035
1036  /**
1037   * Creates a non managed PubSub connection factory and binds it to JNDI.
1038   */

1039  public void createTCF(String JavaDoc name) {
1040    ManagedConnectionFactoryImpl mcf =
1041      new ManagedTopicConnectionFactoryImpl();
1042
1043    try {
1044      mcf.setResourceAdapter(this);
1045      mcf.setCollocated(new Boolean JavaDoc(false));
1046
1047      Object JavaDoc factory = mcf.createConnectionFactory();
1048      bind(name, factory);
1049      if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
1050        AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
1051                                      " - TopicConnectionFactory [" + name
1052                                      + "] has been created and bound.");
1053    } catch (Exception JavaDoc exc) {}
1054  }
1055
1056  /**
1057   * Initiates an admin session.
1058   *
1059   * @exception AdminException If the admin session could not be started.
1060   */

1061  void adminConnect() throws AdminException
1062  {
1063    try {
1064      TopicConnectionFactory JavaDoc factory;
1065
1066      if (isHa) {
1067          if (collocated)
1068              factory = TopicHALocalConnectionFactory.create();
1069          else {
1070              String JavaDoc urlHa = "hajoram://" + hostName + ":" + serverPort;
1071              factory = TopicHATcpConnectionFactory.create(urlHa);
1072          }
1073      } else {
1074      if (collocated)
1075        factory = TopicLocalConnectionFactory.create();
1076      else
1077        factory = TopicTcpConnectionFactory.create(hostName, serverPort);
1078      }
1079
1080      ((org.objectweb.joram.client.jms.ConnectionFactory) factory)
1081        .getParameters().connectingTimer = 60;
1082
1083      joramAdmin = new JoramAdmin(factory, "root", "root");
1084    }
1085    catch (ConnectException JavaDoc exc) {
1086      throw new AdminException("Admin connection can't be established: "
1087                               + exc.getMessage());
1088    }
1089  }
1090
1091  /** Adds a given managed connection to the list of producers. */
1092  void addProducer(ManagedConnectionImpl managedCx)
1093  {
1094    producers.add(managedCx);
1095  }
1096
1097  /** Removes a given managed connection from the list of producers. */
1098  void removeProducer(ManagedConnectionImpl managedCx)
1099  {
1100    producers.remove(managedCx);
1101  }
1102
1103  /** remove prefix name scn:comp/ */
1104  private static String JavaDoc removePrefix(String JavaDoc name) {
1105    String JavaDoc PREFIX_NAME = "scn:comp/";
1106    try {
1107      if (name.startsWith(PREFIX_NAME))
1108        return name.substring(PREFIX_NAME.length());
1109      else
1110        return name;
1111    } catch (Exception JavaDoc e) {
1112      return name;
1113    }
1114  }
1115
1116  /**
1117   * Creates or retrieves a queue destination on the underlying JORAM server,
1118   * (re)binds the corresponding <code>Queue</code> instance.
1119   *
1120   * @param serverId The identifier of the server where deploying the queue.
1121   * @param name The name of the queue.
1122   * @param className The queue class name.
1123   * @param prop The queue properties.
1124   *
1125   * @exception AdminException If the creation fails.
1126   */

1127  public Destination JavaDoc createQueue(int serverId,
1128                                 String JavaDoc name,
1129                                 String JavaDoc className,
1130                                 Properties JavaDoc prop)
1131    throws AdminException {
1132    try {
1133      Context JavaDoc ctx = new InitialContext JavaDoc();
1134      return (Destination JavaDoc) ctx.lookup(name);
1135    } catch (javax.naming.NamingException JavaDoc exc) {
1136      try {
1137        String JavaDoc shortName = removePrefix(name);
1138        Queue queue = Queue.create(serverId,
1139                                   shortName,
1140                                   className,
1141                                   prop);
1142        queue.setFreeReading();
1143        queue.setFreeWriting();
1144        if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
1145          AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
1146                                        " - Queue [" + shortName + "] has been created.");
1147        bind(name, queue);
1148        return queue;
1149      } catch (ConnectException JavaDoc exc2) {
1150        throw new AdminException("createQueue() failed: admin connection "
1151                                 + "has been lost.");
1152      }
1153    }
1154  }
1155
1156  /**
1157   * Creates or retrieves a queue destination on the underlying JORAM server,
1158   * (re)binds the corresponding <code>Queue</code> instance.
1159   *
1160   * @param serverId The identifier of the server where deploying the queue.
1161   * @param name The name of the queue.
1162   *
1163   * @exception AdminException If the creation fails.
1164   */

1165  public Destination JavaDoc createQueue(int serverId, String JavaDoc name)
1166    throws AdminException {
1167    return createQueue(serverId,
1168                       name,
1169                       "org.objectweb.joram.mom.dest.Queue",
1170                       null);
1171  }
1172
1173  /**
1174   * Creates or retrieves a queue destination on the underlying JORAM server,
1175   * (re)binds the corresponding <code>Queue</code> instance.
1176   *
1177   * @param name The name of the queue.
1178   *
1179   * @exception AdminException If the creation fails.
1180   */

1181  public Destination JavaDoc createQueue(String JavaDoc name)
1182    throws AdminException {
1183    try {
1184      return createQueue(joramAdmin.getPlatformAdmin().getLocalServerId(),
1185                         name,
1186                         "org.objectweb.joram.mom.dest.Queue",
1187                         null);
1188    } catch (ConnectException JavaDoc exc2) {
1189      throw new AdminException("createQueue() failed: admin connection "
1190                               + "has been lost.");
1191    }
1192  }
1193
1194  /**
1195   * Creates or retrieves a topic destination on the underlying JORAM server,
1196   * (re)binds the corresponding <code>Topic</code> instance.
1197   *
1198   * @param serverId The identifier of the server where deploying the topic.
1199   * @param name The name of the topic.
1200   * @param className The topic class name.
1201   * @param prop The topic properties.
1202   *
1203   * @exception AdminException If the creation fails.
1204   */

1205  public Destination JavaDoc createTopic(int serverId,
1206                                 String JavaDoc name,
1207                                 String JavaDoc className,
1208                                 Properties JavaDoc prop)
1209    throws AdminException {
1210    try {
1211      Context JavaDoc ctx = new InitialContext JavaDoc();
1212      return (Destination JavaDoc) ctx.lookup(name);
1213    } catch (javax.naming.NamingException JavaDoc exc) {
1214      try {
1215        String JavaDoc shortName = removePrefix(name);
1216        Topic topic = Topic.create(serverId,
1217                                   shortName,
1218                                   className,
1219                                   prop);
1220        topic.setFreeReading();
1221        topic.setFreeWriting();
1222        if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.INFO))
1223          AdapterTracing.dbgAdapter.log(BasicLevel.INFO,
1224                                        " - Topic [" + shortName + "] has been created.");
1225        bind(name, topic);
1226        return topic;
1227      } catch (ConnectException JavaDoc exc2) {
1228        throw new AdminException("createTopic() failed: admin connection "
1229                                 + "has been lost.");
1230      }
1231    }
1232  }
1233
1234  /**
1235   * Creates or retrieves a topic destination on the underlying JORAM server,
1236   * (re)binds the corresponding <code>Topic</code> instance.
1237   *
1238   * @param serverId The identifier of the server where deploying the topic.
1239   * @param name The name of the topic.
1240   *
1241   * @exception AdminException If the creation fails.
1242   */

1243  public Destination JavaDoc createTopic(int serverId, String JavaDoc name)
1244    throws AdminException {
1245    return createTopic(serverId,
1246                       name,
1247                       "org.objectweb.joram.mom.dest.Topic",
1248                       null);
1249  }
1250
1251  /**
1252   * Creates or retrieves a topic destination on the underlying JORAM server,
1253   * (re)binds the corresponding <code>Topic</code> instance.
1254   *
1255   * @param name The name of the topic.
1256   *
1257   * @exception AdminException If the creation fails.
1258   */

1259  public Destination JavaDoc createTopic(String JavaDoc name)
1260    throws AdminException {
1261    try {
1262      return createTopic(joramAdmin.getPlatformAdmin().getLocalServerId(),
1263                         name,
1264                         "org.objectweb.joram.mom.dest.Topic",
1265                         null);
1266    } catch (ConnectException JavaDoc exc2) {
1267      throw new AdminException("createTopic() failed: admin connection "
1268                               + "has been lost.");
1269    }
1270  }
1271
1272  /**
1273   * Remove a destination on the underlying JORAM server
1274   *
1275   * @param name The name of the destination.
1276   */

1277  public void removeDestination(String JavaDoc name)
1278    throws AdminException {
1279    try {
1280      Context JavaDoc ctx = new InitialContext JavaDoc();
1281      Destination JavaDoc dest = (Destination JavaDoc) ctx.lookup(name);
1282      ctx.close();
1283
1284      if (dest instanceof org.objectweb.joram.client.jms.Destination)
1285        ((org.objectweb.joram.client.jms.Destination) dest).delete();
1286      unbind(name);
1287    } catch (Exception JavaDoc exc) {
1288      throw new AdminException("removeDestination(" + name +
1289                               ") failed: use Destination.delete()");
1290    }
1291  }
1292
1293  /** Binds an object to the JNDI context. */
1294  void bind(String JavaDoc name, Object JavaDoc obj) {
1295    try {
1296      Context JavaDoc ctx = new InitialContext JavaDoc();
1297      ctx.rebind(name, obj);
1298      if (! boundNames.contains(name))
1299        boundNames.add(name);
1300    } catch (Exception JavaDoc e) {
1301      if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.WARN))
1302        AdapterTracing.dbgAdapter.log(BasicLevel.WARN,
1303                                      "Binding failed: bind(" + name +"," + obj +")", e);
1304    }
1305  }
1306
1307  /** Unbinds an object from the JNDI context. */
1308  void unbind(String JavaDoc name) {
1309    try {
1310      Context JavaDoc ctx = new InitialContext JavaDoc();
1311      ctx.unbind(name);
1312      boundNames.remove(name);
1313    }
1314    catch (Exception JavaDoc exc) {}
1315  }
1316
1317  /** Deserializing method. */
1318  private void readObject(java.io.ObjectInputStream JavaDoc in)
1319          throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc
1320  {
1321    in.defaultReadObject();
1322    consumers = new Hashtable JavaDoc();
1323    producers = new Vector JavaDoc();
1324  }
1325
1326
1327  // ------------------------------------------
1328
// --- JavaBean setter and getter methods ---
1329
// ------------------------------------------
1330
public void setPlatformConfigDir(java.lang.String JavaDoc platformConfigDir) {
1331    this.platformConfigDir = platformConfigDir;
1332  }
1333
1334  public void setPersistentPlatform(java.lang.Boolean JavaDoc persistentPlatform) {
1335    this.persistentPlatform = persistentPlatform.booleanValue();
1336  }
1337
1338  public void setServerId(java.lang.Short JavaDoc serverId) {
1339    this.serverId = serverId.shortValue();
1340  }
1341
1342  public void setClusterId(java.lang.Short JavaDoc clusterId) {
1343    this.clusterId = clusterId.shortValue();
1344    if (this.clusterId != AgentServer.NULL_ID){
1345        this.isHa = true;
1346    }
1347  }
1348
1349  public void setServerName(java.lang.String JavaDoc serverName) {
1350    this.serverName = serverName;
1351  }
1352
1353  public void setAdminFile(java.lang.String JavaDoc adminFile) {
1354    this.adminFile = adminFile;
1355  }
1356
1357  public void setAdminFileXML(java.lang.String JavaDoc adminFileXML) {
1358    this.adminFileXML = adminFileXML;
1359  }
1360
1361  public void setCollocatedServer(java.lang.Boolean JavaDoc collocatedServer) {
1362    collocated = collocatedServer.booleanValue();
1363  }
1364
1365  public void setHostName(java.lang.String JavaDoc hostName) {
1366    this.hostName = hostName;
1367  }
1368
1369  public void setServerPort(java.lang.Integer JavaDoc serverPort) {
1370    this.serverPort = serverPort.intValue();
1371  }
1372
1373  public void setConnectingTimer(java.lang.Integer JavaDoc connectingTimer) {
1374    this.connectingTimer = connectingTimer.intValue();
1375  }
1376
1377  public void setTxPendingTimer(java.lang.Integer JavaDoc txPendingTimer) {
1378    this.txPendingTimer = txPendingTimer.intValue();
1379  }
1380
1381  public void setCnxPendingTimer(java.lang.Integer JavaDoc cnxPendingTimer) {
1382    this.cnxPendingTimer = cnxPendingTimer.intValue();
1383  }
1384
1385  public void setQueueMessageReadMax(java.lang.Integer JavaDoc queueMessageReadMax) {
1386    this.queueMessageReadMax = queueMessageReadMax.intValue();
1387  }
1388
1389  public void setTopicAckBufferMax(java.lang.Integer JavaDoc topicAckBufferMax) {
1390    this.topicAckBufferMax = topicAckBufferMax.intValue();
1391  }
1392
1393  public void setTopicPassivationThreshold(java.lang.Integer JavaDoc topicPassivationThreshold) {
1394    this.topicPassivationThreshold = topicPassivationThreshold.intValue();
1395  }
1396
1397  public void setTopicActivationThreshold(java.lang.Integer JavaDoc topicActivationThreshold) {
1398    this.topicActivationThreshold = topicActivationThreshold.intValue();
1399  }
1400
1401  public void setAsyncSend(java.lang.Boolean JavaDoc asyncSend) {
1402    this.asyncSend = asyncSend.booleanValue();
1403  }
1404
1405  public void setMultiThreadSync(java.lang.Boolean JavaDoc multiThreadSync) {
1406    this.multiThreadSync = multiThreadSync.booleanValue();
1407  }
1408
1409  public void setMultiThreadSyncDelay(java.lang.Integer JavaDoc multiThreadSyncDelay) {
1410    this.multiThreadSyncDelay = multiThreadSyncDelay.intValue();
1411  }
1412
1413  public java.lang.String JavaDoc getPlatformConfigDir() {
1414    return platformConfigDir;
1415  }
1416
1417  public java.lang.Boolean JavaDoc getPersistentPlatform() {
1418    return new Boolean JavaDoc(persistentPlatform);
1419  }
1420
1421  public Short JavaDoc getServerId() {
1422    return new Short JavaDoc(serverId);
1423  }
1424
1425  public java.lang.String JavaDoc getServerName() {
1426    return serverName;
1427  }
1428
1429  public java.lang.String JavaDoc getAdminFile() {
1430    return adminFile;
1431  }
1432
1433  public java.lang.String JavaDoc getAdminFileXML() {
1434    return adminFileXML;
1435  }
1436
1437  public java.lang.String JavaDoc getAdminFileExportXML() {
1438      return adminFileExportXML;
1439  }
1440
1441  public java.lang.Boolean JavaDoc getCollocatedServer() {
1442    return new Boolean JavaDoc(collocated);
1443  }
1444
1445  public java.lang.String JavaDoc getHostName() {
1446    return hostName;
1447  }
1448
1449  public java.lang.Integer JavaDoc getServerPort() {
1450    return new Integer JavaDoc(serverPort);
1451  }
1452
1453  public java.lang.Integer JavaDoc getConnectingTimer() {
1454    return new Integer JavaDoc(connectingTimer);
1455  }
1456
1457  public java.lang.Integer JavaDoc getTxPendingTimer() {
1458    return new Integer JavaDoc(txPendingTimer);
1459  }
1460
1461  public java.lang.Integer JavaDoc getCnxPendingTimer() {
1462    return new Integer JavaDoc(cnxPendingTimer);
1463  }
1464
1465  public java.lang.Integer JavaDoc getQueueMessageReadMax() {
1466    return new Integer JavaDoc(queueMessageReadMax);
1467  }
1468
1469  public java.lang.Integer JavaDoc getTopicAckBufferMax() {
1470    return new Integer JavaDoc(topicAckBufferMax);
1471  }
1472
1473  public java.lang.Integer JavaDoc getTopicPassivationThreshold() {
1474    return new Integer JavaDoc(topicPassivationThreshold);
1475  }
1476
1477  public java.lang.Integer JavaDoc getTopicActivationThreshold() {
1478    return new Integer JavaDoc(topicActivationThreshold);
1479  }
1480
1481  public java.lang.Boolean JavaDoc getAsyncSend() {
1482    return new Boolean JavaDoc(asyncSend);
1483  }
1484
1485  public java.lang.Boolean JavaDoc getMultiThreadSync() {
1486    return new Boolean JavaDoc(multiThreadSync);
1487  }
1488
1489  public java.lang.Integer JavaDoc getMultiThreadSyncDelay() {
1490    return new Integer JavaDoc(multiThreadSyncDelay);
1491  }
1492
1493
1494  /**
1495   * @return the DeleteDurableSubscription
1496   */

1497  public java.lang.Boolean JavaDoc getDeleteDurableSubscription() {
1498      return new Boolean JavaDoc(deleteDurableSubscription);
1499  }
1500
1501  /**
1502   * Set the deleteDurableSubscription flag
1503   * @param flg to set deleteDurableSubscription
1504   */

1505
1506  public void setDeleteDurableSubscription(java.lang.Boolean JavaDoc flg) {
1507      this.deleteDurableSubscription = flg.booleanValue();
1508  }
1509
1510/**
1511   * Export the repository content to an XML file
1512   * - only the destinations objects are retrieved in this version
1513   * - xml script format of the admin objects (joramAdmin.xml)
1514   * @param exportDir target directory where the export file will be put
1515   * @throws AdminException if an error occurs
1516   */

1517  public void exportRepositoryToFile(String JavaDoc exportDir) throws AdminException {
1518      joramAdmin.exportRepositoryToFile(exportDir);
1519  }
1520
1521  /**
1522   * Reload the joramAdmin.xml file
1523   * @param the path for the joramAdmin file
1524   * @throws AdminException if an error occurs
1525   */

1526  public boolean executeXMLAdminJMX(String JavaDoc path)
1527    throws Exception JavaDoc {
1528      boolean executeAdmin = joramAdmin.executeXMLAdmin(path);
1529      adminConnect();
1530      return executeAdmin;
1531  }
1532}
1533
Popular Tags