Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/ubermq/chord/jms/JMSChordInfrastructure.java


1   package com.ubermq.chord.jms;
2   
3   import com.ubermq.chord.*;
4   import java.io.*;
5   import java.net.*;
6   import java.rmi.*;
7   import java.util.*;
8   
9   /**
10   * The JMS chord infrastructure implementation performs a broadcast
11   * to find nodes that already exist on the network, or takes the URL
12   * of an well-known node.
13   */
14  public class JMSChordInfrastructure
15      extends AbstractChordInfrastructure
16      implements ChordInfrastructure
17  {
18      public static final String DEFAULT_BROADCAST_TOPIC = "com.ubermq.chord.announce";
19      public static final int DEFAULT_REPLICATION_FACTOR = 2;
20  
21      private RemoteChordNode entryPoint;
22      private URI entryPointURI;
23  
24      /**
25       * Creates an infrastructure object with the given well-known
26       * entry point. This method can potentially cache infrastructures
27       * with the same entry point for speed and to reduce memory usage.<P>
28       *
29       * This method determines the finger table size and replication
30       * factor from the existing node.<P>
31       *
32       * @param f an identifier factory
33       * @param url a URI describing the location of an existing, well known node.
34       */
35      public static ChordInfrastructure getInfrastructure(ChordIdentifierFactory f,
36                                                          URI url)
37          throws java.rmi.RemoteException
38      {
39          RemoteChordNode remote = RemoteChordNode.createRemoteInstance(f, url);
40          try
41          {
42              remote.connect();
43          }
44          catch (javax.jms.JMSException e) {
45              throw new RemoteException(e.getMessage());
46          }
47  
48          return new JMSChordInfrastructure(f,
49                                            remote,
50                                            url,
51                                            DEFAULT_REPLICATION_FACTOR);
52      }
53  
54      /**
55       * Creates a JMS chord infrastructure, specifying a well known entry point,
56       * finger table size and replication factor.
57       * @param remote well known node
58       * @param remoteURI well known node URI
59       * @param replication replication factor
60       */
61      private JMSChordInfrastructure(ChordIdentifierFactory f,
62                                     RemoteChordNode remote,
63                                     URI remoteURI,
64                                     int replication)
65      {
66          super(f, replication);
67          this.entryPoint = remote;
68          this.entryPointURI = remoteURI;
69      }
70  
71      public void close()
72      {
73          this.entryPoint.close();
74      }
75  
76      /**
77       * The local entry point node that was used to gain access
78       * to the infrastructure.
79       *
80       * @return a local chord node entry point.
81       */
82      public ChordNode entryPoint()
83      {
84          return this.entryPoint;
85      }
86  
87      /**
88       *  Returns the Service URL of the entry point used to gain access
89       * to the infrastructure.
90       *
91       * @return the url of the entry point.
92       */
93      public URI getEntryPointURI()
94      {
95          return this.entryPointURI;
96      }
97  }