1 20 package org.apache.directory.ldapstudio.proxy.model; 21 22 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 29 35 public class LdapProxy 36 { 37 38 public static final int DEFAULT_TIMEOUT = 30000; 39 40 41 private List <LdapProxyListener> listeners; 42 43 44 private List <LdapMessageWithPDU> receivedLdapMessages; 45 46 private LdapProxyThread proxyThread; 47 48 49 59 public LdapProxy( int localPort, String remoteHost, int remotePort ) 60 { 61 listeners = new ArrayList <LdapProxyListener>(); 62 receivedLdapMessages = new ArrayList <LdapMessageWithPDU>(); 63 proxyThread = new LdapProxyThread( this, localPort, remoteHost, remotePort, DEFAULT_TIMEOUT ); 64 } 65 66 67 72 public void connect() throws IOException 73 { 74 proxyThread.start(); 75 } 76 77 78 81 public void disconnect() 82 { 83 proxyThread.interrupt(); 84 } 85 86 87 93 public void addListener( LdapProxyListener listener ) 94 { 95 listeners.add( listener ); 96 } 97 98 99 105 public void removeListener( LdapProxyListener listener ) 106 { 107 listeners.remove( listener ); 108 } 109 110 111 public boolean addReceivedLdapMessage( LdapMessageWithPDU ldapMessage ) 112 { 113 boolean bool = receivedLdapMessages.add( ldapMessage ); 114 notifyListeners( ldapMessage ); 115 return bool; 116 } 117 118 119 125 private void notifyListeners( LdapMessageWithPDU ldapMessage ) 126 { 127 for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) 128 { 129 LdapProxyListener proxyListener = ( LdapProxyListener ) iter.next(); 130 proxyListener.ldapMessageReceived( ldapMessage ); 131 } 132 } 133 134 135 public List <LdapMessageWithPDU> getReceivedLdapMessages() 136 { 137 return receivedLdapMessages; 138 } 139 } 140 | Popular Tags |