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.socket.apr;
021:
022: import java.net.InetSocketAddress;
023:
024: import org.apache.mina.common.AbstractIoSession;
025: import org.apache.mina.common.DefaultIoFilterChain;
026: import org.apache.mina.common.IoFilterChain;
027: import org.apache.mina.common.IoHandler;
028: import org.apache.mina.common.IoProcessor;
029: import org.apache.mina.common.IoService;
030: import org.apache.mina.common.IoSession;
031: import org.apache.tomcat.jni.Address;
032: import org.apache.tomcat.jni.Socket;
033:
034: /**
035: * {@link IoSession} for the {@link AprSocketConnector}
036: *
037: * @author The Apache MINA Project (dev@mina.apache.org)
038: * @version $Rev: 597276 $, $Date: 2007-11-21 17:44:09 -0700 (Wed, 21 Nov 2007) $
039: */
040: abstract class AprSession extends AbstractIoSession {
041: private long descriptor;
042:
043: private final IoService service;
044: private final IoProcessor<AprSession> processor;
045:
046: private final IoFilterChain filterChain = new DefaultIoFilterChain(
047: this );
048: private final IoHandler handler;
049:
050: private final InetSocketAddress remoteAddress;
051: private final InetSocketAddress localAddress;
052:
053: private boolean readable = true;
054: private boolean writable = true;
055: private boolean interestedInRead;
056: private boolean interestedInWrite;
057:
058: /**
059: * Creates a new instance.
060: */
061: AprSession(IoService service, IoProcessor<AprSession> processor,
062: long descriptor) throws Exception {
063: this .service = service;
064: this .processor = processor;
065: this .handler = service.getHandler();
066: this .descriptor = descriptor;
067:
068: long ra = Address.get(Socket.APR_REMOTE, descriptor);
069: long la = Address.get(Socket.APR_LOCAL, descriptor);
070:
071: this .remoteAddress = new InetSocketAddress(Address.getip(ra),
072: Address.getInfo(ra).port);
073: this .localAddress = new InetSocketAddress(Address.getip(la),
074: Address.getInfo(la).port);
075: }
076:
077: AprSession(IoService service, IoProcessor<AprSession> processor,
078: long descriptor, InetSocketAddress remoteAddress)
079: throws Exception {
080: this .service = service;
081: this .processor = processor;
082: this .handler = service.getHandler();
083: this .descriptor = descriptor;
084:
085: long la = Address.get(Socket.APR_LOCAL, descriptor);
086:
087: this .remoteAddress = remoteAddress;
088: this .localAddress = new InetSocketAddress(Address.getip(la),
089: Address.getInfo(la).port);
090: }
091:
092: long getDescriptor() {
093: return descriptor;
094: }
095:
096: @Override
097: protected IoProcessor<AprSession> getProcessor() {
098: return processor;
099: }
100:
101: public InetSocketAddress getLocalAddress() {
102: return localAddress;
103: }
104:
105: public InetSocketAddress getRemoteAddress() {
106: return remoteAddress;
107: }
108:
109: public IoFilterChain getFilterChain() {
110: return filterChain;
111: }
112:
113: public IoHandler getHandler() {
114: return handler;
115: }
116:
117: public IoService getService() {
118: return service;
119: }
120:
121: @Override
122: public InetSocketAddress getServiceAddress() {
123: return (InetSocketAddress) super .getServiceAddress();
124: }
125:
126: boolean isReadable() {
127: return readable;
128: }
129:
130: void setReadable(boolean readable) {
131: this .readable = readable;
132: }
133:
134: boolean isWritable() {
135: return writable;
136: }
137:
138: void setWritable(boolean writable) {
139: this .writable = writable;
140: }
141:
142: boolean isInterestedInRead() {
143: return interestedInRead;
144: }
145:
146: void setInterestedInRead(boolean isOpRead) {
147: this .interestedInRead = isOpRead;
148: }
149:
150: boolean isInterestedInWrite() {
151: return interestedInWrite;
152: }
153:
154: void setInterestedInWrite(boolean isOpWrite) {
155: this.interestedInWrite = isOpWrite;
156: }
157: }
|