1 package com.ubermq.jms.client.unicast; 2 3 import com.ubermq.jms.client.*; 4 import com.ubermq.jms.client.impl.*; 5 import com.ubermq.kernel.*; 6 import java.io.*; 7 import java.nio.channels.*; 8 9 14 public class UnicastClientSession 15 extends AbstractClientSession 16 implements IClientSession 17 { 18 private IDatagramFactory factory; 19 20 24 public UnicastClientSession(IDatagramFactory f) 25 throws java.io.IOException 26 { 27 super(); 28 this.factory = f; 29 } 30 31 public IConnectionInfo connect(javax.jms.Connection cxn, 32 ConnectionDescriptor descriptor, 33 IMessageProcessor proc) 34 throws java.io.IOException 35 { 36 InternetConnectionDescriptor d = (InternetConnectionDescriptor)descriptor; 38 SocketChannel sc = SocketChannel.open(); 39 40 if (descriptor instanceof IOverflowHandler) 44 { 45 IOverflowHandler overflow = (IOverflowHandler)descriptor; 46 47 while(true) 48 { 49 try { 50 sc.connect(d.getAddress()); 51 break; 52 } catch(IOException iox) { 53 if (overflow.overflow() == IOverflowHandler.ACTION_FAIL) { 54 throw iox; 55 } else { 56 overflow = overflow.getRetryHandler(); 57 58 sc = SocketChannel.open(); 60 } 61 } 62 } 63 } else { 64 sc.connect(d.getAddress()); 65 } 66 67 sc.socket().setTcpNoDelay(true); 69 70 ConnectionInfo i = new SocketChannelConnectionInfo(sc, factory, proc); 72 proc.accept(i); 73 return i; 74 } 75 } 76 | Popular Tags |