1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.mpt;
21
22 import java.net.InetSocketAddress;
23 import java.nio.channels.SocketChannel;
24
25 import org.apache.james.mpt.HostSystem.Continuation;
26
27
28
29
30 public class ExternalSessionFactory implements SessionFactory {
31
32 public static final String IMAP_SHABANG = "* OK IMAP4rev1 Server ready";
33 protected final InetSocketAddress address;
34 protected final Monitor monitor;
35 protected final String shabang;
36
37 public ExternalSessionFactory(final String host, final int port, final Monitor monitor, final String shabang) {
38 super();
39 this.address = new InetSocketAddress(host, port);
40 this.monitor = monitor;
41 this.shabang = shabang;
42 }
43
44 public Session newSession(Continuation continuation) throws Exception {
45 monitor.note("Connecting to " + address.getHostName() + ":" + address.getPort());
46 final SocketChannel channel = SocketChannel.open(address);
47 channel.configureBlocking(false);
48 final ExternalSession result = new ExternalSession(channel, monitor, shabang);
49 return result;
50 }
51
52 public void reset() throws Exception {
53 monitor.note("Please reset system.");
54 }
55
56
57
58
59
60
61
62
63 public String toString()
64 {
65 final String TAB = " ";
66
67 String retValue = "ExternalSessionFactory ( "
68 + "address = " + this.address + TAB
69 + "monitor = " + this.monitor + TAB
70 + "shabang = " + this.shabang + TAB
71 + " )";
72
73 return retValue;
74 }
75 }