KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > jms > server > journal > impl > SingletonArbiter


1 package com.ubermq.jms.server.journal.impl;
2
3 import com.ubermq.jms.server.journal.*;
4 import com.ubermq.kernel.*;
5 import java.io.*;
6
7 /**
8  * Forwards messages to the most recently connected node. It completely forgets
9  * about nodes previously connected. This is used for durable subscriptions to
10  * topics.
11  */

12 public class SingletonArbiter
13     implements DurableConnectionArbiter
14 {
15     private DatagramSink theNode;
16
17     public SingletonArbiter()
18     {
19         theNode = null;
20     }
21
22     public void output(IDatagram d,
23                        IOverflowHandler h)
24         throws IOException
25     {
26         if (theNode != null)
27             theNode.output(d, h);
28         else throw new IOException();
29     }
30
31     public boolean isOpen()
32     {
33         return (theNode != null && theNode.isOpen());
34     }
35
36     public void connect(DatagramSink cdn)
37     {
38         theNode = cdn;
39     }
40
41     public void disconnect(DatagramSink cdn)
42     {
43         if (theNode.equals(cdn))
44             theNode = null;
45     }
46
47     public void disconnectAll()
48     {
49         theNode = null;
50     }
51
52     /**
53      * Returns an informative representation of this
54      * arbiter in HTML.
55      *
56      * @return an HTML rendering of this arbiter's state.
57      */

58     public String JavaDoc toHtml()
59     {
60         if (theNode != null)
61             return "<b>Connection: </b>" + AbstractMultipleArbiter.getDisplayName(theNode);
62         else
63             return "<b>Disconnected</b>";
64     }
65
66
67 }
68
Popular Tags