001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *
019: */
020: package org.apache.mina.transport.vmpipe;
021:
022: import java.util.concurrent.BlockingQueue;
023: import java.util.concurrent.LinkedBlockingQueue;
024: import java.util.concurrent.locks.Lock;
025: import java.util.concurrent.locks.ReentrantLock;
026:
027: import org.apache.mina.common.AbstractIoSession;
028: import org.apache.mina.common.DefaultTransportMetadata;
029: import org.apache.mina.common.IoFilterChain;
030: import org.apache.mina.common.IoHandler;
031: import org.apache.mina.common.IoProcessor;
032: import org.apache.mina.common.IoService;
033: import org.apache.mina.common.IoServiceListenerSupport;
034: import org.apache.mina.common.IoSession;
035: import org.apache.mina.common.TransportMetadata;
036: import org.apache.mina.common.WriteRequestQueue;
037:
038: /**
039: * A {@link IoSession} for in-VM transport (VM_PIPE).
040: *
041: * @author The Apache MINA Project (dev@mina.apache.org)
042: * @version $Rev: 597545 $, $Date: 2007-11-22 22:02:30 -0700 (Thu, 22 Nov 2007) $
043: */
044: class VmPipeSessionImpl extends AbstractIoSession implements
045: VmPipeSession {
046:
047: static final TransportMetadata METADATA = new DefaultTransportMetadata(
048: "mina", "vmpipe", false, false, VmPipeAddress.class,
049: VmPipeSessionConfig.class, Object.class);
050:
051: private static final VmPipeSessionConfig CONFIG = new DefaultVmPipeSessionConfig();
052:
053: private final IoService service;
054:
055: private final IoServiceListenerSupport serviceListeners;
056:
057: private final VmPipeAddress localAddress;
058:
059: private final VmPipeAddress remoteAddress;
060:
061: private final VmPipeAddress serviceAddress;
062:
063: private final IoHandler handler;
064:
065: private final VmPipeFilterChain filterChain;
066:
067: private final VmPipeSessionImpl remoteSession;
068:
069: private final Lock lock;
070:
071: final BlockingQueue<Object> receivedMessageQueue;
072:
073: /*
074: * Constructor for client-side session.
075: */
076: VmPipeSessionImpl(IoService service,
077: IoServiceListenerSupport serviceListeners,
078: VmPipeAddress localAddress, IoHandler handler,
079: VmPipe remoteEntry) {
080: this .service = service;
081: this .serviceListeners = serviceListeners;
082: this .lock = new ReentrantLock();
083: this .localAddress = localAddress;
084: this .remoteAddress = this .serviceAddress = remoteEntry
085: .getAddress();
086: this .handler = handler;
087: this .filterChain = new VmPipeFilterChain(this );
088: this .receivedMessageQueue = new LinkedBlockingQueue<Object>();
089:
090: remoteSession = new VmPipeSessionImpl(this , remoteEntry);
091: }
092:
093: /*
094: * Constructor for server-side session.
095: */
096: private VmPipeSessionImpl(VmPipeSessionImpl remoteSession,
097: VmPipe entry) {
098: this .service = entry.getAcceptor();
099: this .serviceListeners = entry.getListeners();
100: this .lock = remoteSession.lock;
101: this .localAddress = this .serviceAddress = remoteSession.remoteAddress;
102: this .remoteAddress = remoteSession.localAddress;
103: this .handler = entry.getHandler();
104: this .filterChain = new VmPipeFilterChain(this );
105: this .remoteSession = remoteSession;
106: this .receivedMessageQueue = new LinkedBlockingQueue<Object>();
107: }
108:
109: public IoService getService() {
110: return service;
111: }
112:
113: @Override
114: protected IoProcessor<VmPipeSessionImpl> getProcessor() {
115: return filterChain.getProcessor();
116: }
117:
118: IoServiceListenerSupport getServiceListeners() {
119: return serviceListeners;
120: }
121:
122: public VmPipeSessionConfig getConfig() {
123: return CONFIG;
124: }
125:
126: public IoFilterChain getFilterChain() {
127: return filterChain;
128: }
129:
130: public VmPipeSessionImpl getRemoteSession() {
131: return remoteSession;
132: }
133:
134: public IoHandler getHandler() {
135: return handler;
136: }
137:
138: public TransportMetadata getTransportMetadata() {
139: return METADATA;
140: }
141:
142: public VmPipeAddress getRemoteAddress() {
143: return remoteAddress;
144: }
145:
146: public VmPipeAddress getLocalAddress() {
147: return localAddress;
148: }
149:
150: @Override
151: public VmPipeAddress getServiceAddress() {
152: return serviceAddress;
153: }
154:
155: WriteRequestQueue getWriteRequestQueue0() {
156: return super .getWriteRequestQueue();
157: }
158:
159: Lock getLock() {
160: return lock;
161: }
162: }
|