| 1 package com.ubermq.jms.server.journal.impl; 2 3 import com.ubermq.jms.server.journal.*; 4 import com.ubermq.jms.common.routing.impl.*; 5 import com.ubermq.kernel.*; 6 import java.io.*; 7 import java.util.*; 8 9 20 public class FailoverArbiter 21 implements DurableConnectionArbiter 22 { 23 private transient DatagramSink active; 24 private transient LinkedList cxns; 25 26 public static final long serialVersionUID = 1L; 27 28 31 public FailoverArbiter() 32 { 33 cxns = new LinkedList(); 34 } 35 36 private void readObject(ObjectInputStream ois) 37 throws IOException, ClassNotFoundException  38 { 39 ois.defaultReadObject(); 40 cxns = new LinkedList(); 41 } 42 43 49 private void nextConnection() 50 { 51 if (cxns.size() > 0) { 52 active = (DatagramSink)cxns.removeFirst(); 53 } else { 54 active = null; 55 } 56 } 57 58 65 public void output(IDatagram d, 66 IOverflowHandler h) 67 throws IOException 68 { 69 if (isOpen()) { 70 try { 71 active.output(d, h); 72 } catch(IOException iox) { 73 nextConnection(); 76 throw iox; 77 } 78 } 79 else 80 throw new IOException("not open"); 81 } 82 83 87 public boolean isOpen() 88 { 89 return (active != null); 90 } 91 92 95 public void disconnect(DatagramSink cdn) 96 { 97 if (cdn.equals(active)) { 98 nextConnection(); 99 } else { 100 cxns.remove(cdn); 101 } 102 } 103 104 107 public void disconnectAll() 108 { 109 active = null; 110 cxns.clear(); 111 } 112 113 117 public void connect(DatagramSink cdn) 118 { 119 if (active == null) 120 active = cdn; 121 else { 122 cxns.addLast(cdn); 123 } 124 } 125 126 public String toString() 127 { 128 return "Active Proxy: " + active + " Backups: " + cxns; 129 } 130 131 public String toHtml() 132 { 133 if (active != null) 134 { 135 StringBuffer sb = new StringBuffer (); 136 sb.append(AbstractMultipleArbiter.getDisplayName(active)); 137 sb.append(" <I>(Active)</I><br>"); 138 139 Iterator iter = cxns.iterator(); 140 while (iter.hasNext()) 141 { 142 sb.append(AbstractMultipleArbiter.getDisplayName((DatagramSink)iter.next())); 143 sb.append("<br>"); 144 } 145 146 return sb.toString(); 147 } 148 else 149 { 150 return "<b>Disconnected</b>"; 151 } 152 } 153 } 154 | Popular Tags |