1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.transport.vmpipe;
21
22 import java.util.concurrent.BlockingQueue;
23 import java.util.concurrent.LinkedBlockingQueue;
24 import java.util.concurrent.locks.Lock;
25 import java.util.concurrent.locks.ReentrantLock;
26
27 import org.apache.mina.core.filterchain.IoFilterChain;
28 import org.apache.mina.core.service.DefaultTransportMetadata;
29 import org.apache.mina.core.service.IoHandler;
30 import org.apache.mina.core.service.IoProcessor;
31 import org.apache.mina.core.service.IoService;
32 import org.apache.mina.core.service.IoServiceListenerSupport;
33 import org.apache.mina.core.service.TransportMetadata;
34 import org.apache.mina.core.session.AbstractIoSession;
35 import org.apache.mina.core.session.IoSession;
36 import org.apache.mina.core.write.WriteRequestQueue;
37
38
39
40
41
42
43
44 class VmPipeSession extends AbstractIoSession {
45
46 static final TransportMetadata METADATA =
47 new DefaultTransportMetadata(
48 "mina", "vmpipe", false, false,
49 VmPipeAddress.class,
50 VmPipeSessionConfig.class,
51 Object.class);
52
53 private static final VmPipeSessionConfig CONFIG = new DefaultVmPipeSessionConfig();
54
55 private final IoService service;
56
57 private final IoServiceListenerSupport serviceListeners;
58
59 private final VmPipeAddress localAddress;
60
61 private final VmPipeAddress remoteAddress;
62
63 private final VmPipeAddress serviceAddress;
64
65 private final IoHandler handler;
66
67 private final VmPipeFilterChain filterChain;
68
69 private final VmPipeSession remoteSession;
70
71 private final Lock lock;
72
73 final BlockingQueue<Object> receivedMessageQueue;
74
75
76
77
78 VmPipeSession(IoService service,
79 IoServiceListenerSupport serviceListeners,
80 VmPipeAddress localAddress, IoHandler handler, VmPipe remoteEntry) {
81 this.service = service;
82 this.serviceListeners = serviceListeners;
83 lock = new ReentrantLock();
84 this.localAddress = localAddress;
85 remoteAddress = serviceAddress = remoteEntry.getAddress();
86 this.handler = handler;
87 filterChain = new VmPipeFilterChain(this);
88 receivedMessageQueue = new LinkedBlockingQueue<Object>();
89
90 remoteSession = new VmPipeSession(this, remoteEntry);
91 }
92
93
94
95
96 private VmPipeSession(VmPipeSession remoteSession, VmPipe entry) {
97 service = entry.getAcceptor();
98 serviceListeners = entry.getListeners();
99 lock = remoteSession.lock;
100 localAddress = serviceAddress = remoteSession.remoteAddress;
101 remoteAddress = remoteSession.localAddress;
102 handler = entry.getHandler();
103 filterChain = new VmPipeFilterChain(this);
104 this.remoteSession = remoteSession;
105 receivedMessageQueue = new LinkedBlockingQueue<Object>();
106 }
107
108 public IoService getService() {
109 return service;
110 }
111
112 @Override
113 public IoProcessor<VmPipeSession> getProcessor() {
114 return filterChain.getProcessor();
115 }
116
117 IoServiceListenerSupport getServiceListeners() {
118 return serviceListeners;
119 }
120
121 public VmPipeSessionConfig getConfig() {
122 return CONFIG;
123 }
124
125 public IoFilterChain getFilterChain() {
126 return filterChain;
127 }
128
129 public VmPipeSession getRemoteSession() {
130 return remoteSession;
131 }
132
133 public IoHandler getHandler() {
134 return handler;
135 }
136
137 public TransportMetadata getTransportMetadata() {
138 return METADATA;
139 }
140
141 public VmPipeAddress getRemoteAddress() {
142 return remoteAddress;
143 }
144
145 public VmPipeAddress getLocalAddress() {
146 return localAddress;
147 }
148
149 @Override
150 public VmPipeAddress getServiceAddress() {
151 return serviceAddress;
152 }
153
154 void increaseWrittenBytes0(int increment, long currentTime) {
155 super.increaseWrittenBytes(increment, currentTime);
156 }
157
158 WriteRequestQueue getWriteRequestQueue0() {
159 return super.getWriteRequestQueue();
160 }
161
162 Lock getLock() {
163 return lock;
164 }
165 }