1 3 package org.jgroups; 4 5 6 import java.io.Serializable ; 7 import java.util.Vector ; 8 9 10 11 12 44 public abstract class Channel implements Transport { 45 public static final int BLOCK=0; 46 public static final int VIEW=1; 47 public static final int SUSPECT=2; 48 public static final int LOCAL=3; 49 public static final int GET_STATE_EVENTS=4; 50 public static final int AUTO_RECONNECT=5; 51 public static final int AUTO_GETSTATE=6; 52 53 54 protected UpHandler up_handler=null; protected ChannelListener channel_listener=null; 56 57 58 74 abstract public void connect(String channel_name) throws ChannelException, ChannelClosedException; 75 76 77 81 abstract public void disconnect(); 82 83 84 90 abstract public void close(); 91 92 93 98 public void open() throws ChannelException { 99 ; 100 } 101 102 103 106 abstract public boolean isOpen(); 107 108 109 113 abstract public boolean isConnected(); 114 115 116 124 public int getNumMessages() { 125 return -1; 126 } 127 128 129 148 abstract public void send(Message msg) throws ChannelNotConnectedException, ChannelClosedException; 149 150 151 159 abstract public void send(Address dst, Address src, Serializable obj) throws ChannelNotConnectedException, 160 ChannelClosedException; 161 162 163 168 public void down(Event evt) { 169 } 170 171 172 205 abstract public Object receive(long timeout) throws ChannelNotConnectedException, 206 ChannelClosedException, TimeoutException; 207 208 209 224 abstract public Object peek(long timeout) throws ChannelNotConnectedException, ChannelClosedException, TimeoutException; 225 226 227 236 abstract public View getView(); 237 238 239 247 abstract public Address getLocalAddress(); 248 249 250 256 abstract public String getChannelName(); 257 258 259 266 public void setUpHandler(UpHandler up_handler) { 267 this.up_handler=up_handler; 268 } 269 270 271 276 public void setChannelListener(ChannelListener channel_listener) { 277 this.channel_listener=channel_listener; 278 } 279 280 281 303 abstract public void setOpt(int option, Object value); 304 305 306 313 abstract public Object getOpt(int option); 314 315 316 321 abstract public void blockOk(); 322 323 324 339 abstract public boolean getState(Address target, long timeout) 340 throws ChannelNotConnectedException, ChannelClosedException; 341 342 343 358 abstract public boolean getAllStates(Vector targets, long timeout) 359 throws ChannelNotConnectedException, ChannelClosedException; 360 361 362 368 public abstract void returnState(byte[] state); 369 370 371 public static String option2String(int option) { 372 switch(option) { 373 case BLOCK: 374 return "BLOCK"; 375 case VIEW: 376 return "VIEW"; 377 case SUSPECT: 378 return "SUSPECT"; 379 case LOCAL: 380 return "LOCAL"; 381 case GET_STATE_EVENTS: 382 return "GET_STATE_EVENTS"; 383 case AUTO_RECONNECT: 384 return "AUTO_RECONNECT"; 385 case AUTO_GETSTATE: 386 return "AUTO_GETSTATE"; 387 default: 388 return "unknown (" + option + ')'; 389 } 390 } 391 } 392 | Popular Tags |