[Beepcore-java-commits] CVS: beepcore-java/src/org/beepcore/beep/transport/tcp TCPSessionCreator.jav
Status: Beta
Brought to you by:
huston
From: Huston F. <hu...@us...> - 2001-11-08 03:59:40
|
Update of /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/transport/tcp In directory usw-pr-cvs1:/tmp/cvs-serv21487/src/org/beepcore/beep/transport/tcp Modified Files: TCPSessionCreator.java TCPSession.java Log Message: Made ProfileRegistry optional for TCPSessionCreator.initiate() Index: TCPSessionCreator.java =================================================================== RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/transport/tcp/TCPSessionCreator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** TCPSessionCreator.java 2001/10/31 02:03:41 1.3 --- TCPSessionCreator.java 2001/11/08 03:59:37 1.4 *************** *** 67,78 **** private static Hashtable listenerSockets = null; - private static final int CHANNEL_START_ODD = 1; - private static final int CHANNEL_START_EVEN = 2; - /** * Method initiate * * ! * @param sock * @param registry * --- 67,76 ---- private static Hashtable listenerSockets = null; /** * Method initiate * * ! * @param host ! * @param port * @param registry * *************** *** 80,88 **** * */ ! public static TCPSession initiate(Socket sock, ProfileRegistry registry) throws BEEPException { ! return new TCPSession(sock, (ProfileRegistry) registry.clone(), ! CHANNEL_START_ODD, null, null, null); } --- 78,90 ---- * */ ! public static TCPSession initiate(InetAddress host, int port) throws BEEPException { ! try { ! return TCPSession.createInitiator(new Socket(host, port), ! new ProfileRegistry()); ! } catch (IOException x) { ! throw new BEEPException(x.getMessage()); ! } } *************** *** 102,121 **** throws BEEPException { - - // Connect and create TCPSession with the socket - Socket socket; try { ! socket = new Socket(host, port); } catch (IOException x) { throw new BEEPException(x.getMessage()); } - - if (socket == null) { - throw new BEEPException(ERR_TCP_SOCKET_FAILURE); - } - - TCPSession t = TCPSessionCreator.initiate(socket, registry); - - return t; } --- 104,113 ---- throws BEEPException { try { ! return TCPSession.createInitiator(new Socket(host, port), ! registry); } catch (IOException x) { throw new BEEPException(x.getMessage()); } } *************** *** 132,141 **** * */ ! public static TCPSession initiate(String host, int port, ! ProfileRegistry registry) throws BEEPException { try { ! return initiate(InetAddress.getByName(host), port, registry); } catch (UnknownHostException x) { throw new BEEPException("Unable to connect, unkown host"); --- 124,132 ---- * */ ! public static TCPSession initiate(String host, int port) throws BEEPException { try { ! return initiate(InetAddress.getByName(host), port); } catch (UnknownHostException x) { throw new BEEPException("Unable to connect, unkown host"); *************** *** 144,161 **** /** ! * Method listen * * ! * @param sock ! * @param registry * * @throws BEEPException * */ ! public static TCPSession listen(Socket sock, ProfileRegistry registry) ! throws BEEPException { ! return new TCPSession(sock, (ProfileRegistry) registry.clone(), ! CHANNEL_START_EVEN, null, null, null); } --- 135,158 ---- /** ! * Method initiate * * ! * @param host ! * @param port ! * @param profiles ! * @param ccls * * @throws BEEPException * */ ! public static TCPSession initiate(String host, int port, ! ProfileRegistry registry) ! throws BEEPException { ! try { ! return initiate(InetAddress.getByName(host), port, registry); ! } catch (UnknownHostException x) { ! throw new BEEPException("Unable to connect, unkown host"); ! } } *************** *** 224,228 **** peer = socket.accept(); ! return TCPSessionCreator.listen(peer, registry); } catch (Exception e) { throw new BEEPException(e.getMessage()); --- 221,225 ---- peer = socket.accept(); ! return TCPSession.createListener(peer, registry); } catch (Exception e) { throw new BEEPException(e.getMessage()); *************** *** 246,250 **** { try { - TCPSession temp = null; InetAddress addr = null; --- 243,246 ---- *************** *** 253,289 **** } ! temp = listen(addr, port, registry); ! ! return temp; } catch (UnknownHostException x) { throw new BEEPException(x.getMessage()); } - } - - /** - * Accessible only from TCPSession (kinda slick) - */ - static TCPSession initiate(Socket sock, ProfileRegistry registry, - SessionCredential localCred, - SessionCredential peerCred, - SessionTuningProperties tuning) - throws BEEPException - { - return new TCPSession(sock, (ProfileRegistry) registry.clone(), - CHANNEL_START_ODD, localCred, peerCred, tuning); - } - - /** - * Accessible only from TCPSession (reset() specifically) - */ - static TCPSession listen(Socket sock, ProfileRegistry registry, - SessionCredential localCred, - SessionCredential peerCred, - SessionTuningProperties tuning) - throws BEEPException - { - return new TCPSession(sock, (ProfileRegistry) registry.clone(), - CHANNEL_START_EVEN, localCred, peerCred, - tuning); } } --- 249,256 ---- } ! return listen(addr, port, registry); } catch (UnknownHostException x) { throw new BEEPException(x.getMessage()); } } } Index: TCPSession.java =================================================================== RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/transport/tcp/TCPSession.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** TCPSession.java 2001/10/31 00:32:38 1.13 --- TCPSession.java 2001/11/08 03:59:37 1.14 *************** *** 70,73 **** --- 70,77 ---- private static final String CRLF = "\r\n"; + private static final int CHANNEL_START_ODD = 1; + private static final int CHANNEL_START_EVEN = 2; + + // Instance Data // @todo had these per stack, but have *************** *** 109,115 **** * @throws BEEPException */ ! TCPSession(Socket sock, ProfileRegistry registry, int firstChannel, ! SessionCredential localCred, SessionCredential peerCred, ! SessionTuningProperties tuning) throws BEEPException { --- 113,119 ---- * @throws BEEPException */ ! private TCPSession(Socket sock, ProfileRegistry registry, int firstChannel, ! SessionCredential localCred, SessionCredential peerCred, ! SessionTuningProperties tuning) throws BEEPException { *************** *** 133,136 **** --- 137,176 ---- } + /** + * Method initiate + * + * + * @param sock + * @param registry + * + * @throws BEEPException + * + */ + public static TCPSession createInitiator(Socket sock, + ProfileRegistry registry) + throws BEEPException + { + return new TCPSession(sock, (ProfileRegistry) registry.clone(), + CHANNEL_START_ODD, null, null, null); + } + + /** + * Method listen + * + * + * @param sock + * @param registry + * + * @throws BEEPException + * + */ + public static TCPSession createListener(Socket sock, + ProfileRegistry registry) + throws BEEPException + { + return new TCPSession(sock, (ProfileRegistry) registry.clone(), + CHANNEL_START_EVEN, null, null, null); + } + // Overrides method in Session public synchronized void close() throws BEEPException *************** *** 279,287 **** if (isInitiator()) { ! return TCPSessionCreator.initiate(s, reg, localCred, peerCred, ! tuning); } else { ! return TCPSessionCreator.listen(s, reg, localCred, peerCred, ! tuning); } } --- 319,327 ---- if (isInitiator()) { ! return new TCPSession(s, reg, CHANNEL_START_ODD, ! localCred, peerCred, tuning); } else { ! return new TCPSession(s, reg, CHANNEL_START_EVEN, ! localCred, peerCred, tuning); } } |