mina-1.1.7.dfsg/ 0000755 0001750 0001750 00000000000 11044712500 013254 5 ustar drazzib drazzib mina-1.1.7.dfsg/docs/ 0000755 0001750 0001750 00000000000 11044712500 014204 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/ 0000755 0001750 0001750 00000000000 11044712500 015340 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/pom.xml 0000644 0001750 0001750 00000001642 11002320016 016647 0 ustar drazzib drazzib
4.0.0org.apache.minabuild1.1.7mina-filter-sslApache MINA SSL Filterjarorg.apache.minamina-core${pom.version}compileorg.slf4jslf4j-simple1.4.3test
mina-1.1.7.dfsg/filter-ssl/src/ 0000755 0001750 0001750 00000000000 11002320014 016114 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/ 0000755 0001750 0001750 00000000000 11002320015 017041 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/resources/ 0000755 0001750 0001750 00000000000 11002320015 021053 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/resources/META-INF/ 0000755 0001750 0001750 00000000000 11044712500 022225 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/resources/META-INF/LICENSE.jzlib.txt 0000644 0001750 0001750 00000003161 11002320016 025151 0 ustar drazzib drazzib JZlib 0.0.* were released under the GNU LGPL license. Later, we have switched
over to a BSD-style license.
------------------------------------------------------------------------------
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mina-1.1.7.dfsg/filter-ssl/src/main/resources/META-INF/LICENSE.txt 0000644 0001750 0001750 00000024157 11002320016 024050 0 ustar drazzib drazzib Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
mina-1.1.7.dfsg/filter-ssl/src/main/resources/META-INF/LICENSE.slf4j.txt 0000644 0001750 0001750 00000002755 11002320016 025071 0 ustar drazzib drazzib Copyright (c) 2004-2005 SLF4J.ORG
Copyright (c) 2004-2005 QOS.ch
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, provided that the above
copyright notice(s) and this permission notice appear in all copies of
the Software and that both the above copyright notice(s) and this
permission notice appear in supporting documentation.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Except as contained in this notice, the name of a copyright holder
shall not be used in advertising or otherwise to promote the sale, use
or other dealings in this Software without prior written authorization
of the copyright holder.
mina-1.1.7.dfsg/filter-ssl/src/main/resources/META-INF/NOTICE.txt 0000644 0001750 0001750 00000001517 11002320016 023742 0 ustar drazzib drazzib Apache MINA
Copyright 2007 The Apache Software Foundation.
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
Message logging is provided by the SLF4J library package,
which is open source software, written by Ceki Gülcü, and
copyright by SLF4J.ORG and QOS.ch. The original software is
available from
http://www.slf4j.org/
Data compression support is provided by the JZLib library package,
which is open source software, written by JCraft, and copyright
by JCraft. The original software is available from
http://www.jcraft.com/jzlib/
Spring framework is provided by the Spring framework library
package, which is open source software, written by Rod Johnson
et al, and copyright by Springframework.org. The original
software is available from
http://www.springframework.org/
mina-1.1.7.dfsg/filter-ssl/src/main/resources/META-INF/LICENSE.springframework.txt 0000644 0001750 0001750 00000024157 11002320016 027267 0 ustar drazzib drazzib Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
mina-1.1.7.dfsg/filter-ssl/src/main/java/ 0000755 0001750 0001750 00000000000 11002320014 017761 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/java/org/ 0000755 0001750 0001750 00000000000 11002320014 020550 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/java/org/apache/ 0000755 0001750 0001750 00000000000 11002320014 021771 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/java/org/apache/mina/ 0000755 0001750 0001750 00000000000 11002320014 022715 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/java/org/apache/mina/filter/ 0000755 0001750 0001750 00000000000 11044712500 024215 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/java/org/apache/mina/filter/SSLFilter.java 0000644 0001750 0001750 00000056514 11002320015 026670 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.filter;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSession;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.ByteBufferProxy;
import org.apache.mina.common.IoFilterAdapter;
import org.apache.mina.common.IoFilterChain;
import org.apache.mina.common.IoFuture;
import org.apache.mina.common.IoFutureListener;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.WriteFuture;
import org.apache.mina.common.support.DefaultWriteFuture;
import org.apache.mina.filter.support.SSLHandler;
import org.apache.mina.util.SessionLog;
/**
* An SSL filter that encrypts and decrypts the data exchanged in the session.
* Adding this filter triggers SSL handshake procedure immediately by sending
* a SSL 'hello' message, so you don't need to call
* {@link #startSSL(IoSession)} manually unless you are implementing StartTLS
* (see below).
*
* This filter uses an {@link SSLEngine} which was introduced in Java 5, so
* Java version 5 or above is mandatory to use this filter. And please note that
* this filter only works for TCP/IP connections.
*
* This filter logs debug information using {@link SessionLog}.
*
*
Implementing StartTLS
*
* You can use {@link #DISABLE_ENCRYPTION_ONCE} attribute to implement StartTLS:
*
* public void messageReceived(IoSession session, Object message) {
* if (message instanceof MyStartTLSRequest) {
* // Insert SSLFilter to get ready for handshaking
* session.getFilterChain().addFirst(sslFilter);
*
* // Disable encryption temporarilly.
* // This attribute will be removed by SSLFilter
* // inside the Session.write() call below.
* session.setAttribute(SSLFilter.DISABLE_ENCRYPTION_ONCE, Boolean.TRUE);
*
* // Write StartTLSResponse which won't be encrypted.
* session.write(new MyStartTLSResponse(OK));
*
* // Now DISABLE_ENCRYPTION_ONCE attribute is cleared.
* assert session.getAttribute(SSLFilter.DISABLE_ENCRYPTION_ONCE) == null;
* }
* }
*
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 587373 $, $Date: 2007-10-23 11:54:05 +0900 (Tue, 23 Oct 2007) $
*/
public class SSLFilter extends IoFilterAdapter {
/**
* A session attribute key that stores underlying {@link SSLSession}
* for each session.
*/
public static final String SSL_SESSION = SSLFilter.class.getName()
+ ".SSLSession";
/**
* A session attribute key that makes next one write request bypass
* this filter (not encrypting the data). This is a marker attribute,
* which means that you can put whatever as its value. ({@link Boolean#TRUE}
* is preferred.) The attribute is automatically removed from the session
* attribute map as soon as {@link IoSession#write(Object)} is invoked,
* and therefore should be put again if you want to make more messages
* bypass this filter. This is especially useful when you implement
* StartTLS.
*/
public static final String DISABLE_ENCRYPTION_ONCE = SSLFilter.class
.getName()
+ ".DisableEncryptionOnce";
/**
* A session attribute key that makes this filter to emit a
* {@link IoHandler#messageReceived(IoSession, Object)} event with a
* special message ({@link #SESSION_SECURED} or {@link #SESSION_UNSECURED}).
* This is a marker attribute, which means that you can put whatever as its
* value. ({@link Boolean#TRUE} is preferred.) By default, this filter
* doesn't emit any events related with SSL session flow control.
*/
public static final String USE_NOTIFICATION = SSLFilter.class.getName()
+ ".UseNotification";
/**
* A special message object which is emitted with a {@link IoHandler#messageReceived(IoSession, Object)}
* event when the session is secured and its {@link #USE_NOTIFICATION}
* attribute is set.
*/
public static final SSLFilterMessage SESSION_SECURED = new SSLFilterMessage(
"SESSION_SECURED");
/**
* A special message object which is emitted with a {@link IoHandler#messageReceived(IoSession, Object)}
* event when the session is not secure anymore and its {@link #USE_NOTIFICATION}
* attribute is set.
*/
public static final SSLFilterMessage SESSION_UNSECURED = new SSLFilterMessage(
"SESSION_UNSECURED");
private static final String NEXT_FILTER = SSLFilter.class.getName()
+ ".NextFilter";
private static final String SSL_HANDLER = SSLFilter.class.getName()
+ ".SSLHandler";
// SSL Context
private SSLContext sslContext;
private boolean client;
private boolean needClientAuth;
private boolean wantClientAuth;
private String[] enabledCipherSuites;
private String[] enabledProtocols;
/**
* Creates a new SSL filter using the specified {@link SSLContext}.
*/
public SSLFilter(SSLContext sslContext) {
if (sslContext == null) {
throw new NullPointerException("sslContext");
}
this.sslContext = sslContext;
}
/**
* Returns the underlying {@link SSLSession} for the specified session.
*
* @return null if no {@link SSLSession} is initialized yet.
*/
public SSLSession getSSLSession(IoSession session) {
return (SSLSession) session.getAttribute(SSL_SESSION);
}
/**
* (Re)starts SSL session for the specified session if not started yet.
* Please note that SSL session is automatically started by default, and therefore
* you don't need to call this method unless you've used TLS closure.
*
* @return true if the SSL session has been started, false if already started.
* @throws SSLException if failed to start the SSL session
*/
public boolean startSSL(IoSession session) throws SSLException {
SSLHandler handler = getSSLSessionHandler(session);
boolean started;
synchronized (handler) {
if (handler.isOutboundDone()) {
NextFilter nextFilter = (NextFilter) session
.getAttribute(NEXT_FILTER);
handler.destroy();
handler.init();
handler.handshake(nextFilter);
started = true;
} else {
started = false;
}
}
handler.flushScheduledEvents();
return started;
}
/**
* Returns true if and only if the specified session is
* encrypted/decrypted over SSL/TLS currently. This method will start
* to retun false after TLS close_notify message
* is sent and any messages written after then is not goinf to get encrypted.
*/
public boolean isSSLStarted(IoSession session) {
SSLHandler handler = getSSLSessionHandler0(session);
if (handler == null) {
return false;
}
synchronized (handler) {
return !handler.isOutboundDone();
}
}
/**
* Stops the SSL session by sending TLS close_notify message to
* initiate TLS closure.
*
* @param session the {@link IoSession} to initiate TLS closure
* @throws SSLException if failed to initiate TLS closure
* @throws IllegalArgumentException if this filter is not managing the specified session
*/
public WriteFuture stopSSL(IoSession session) throws SSLException {
SSLHandler handler = getSSLSessionHandler(session);
NextFilter nextFilter = (NextFilter) session.getAttribute(NEXT_FILTER);
WriteFuture future;
synchronized (handler) {
future = initiateClosure(nextFilter, session);
}
handler.flushScheduledEvents();
return future;
}
/**
* Returns true if the engine is set to use client mode
* when handshaking.
*/
public boolean isUseClientMode() {
return client;
}
/**
* Configures the engine to use client (or server) mode when handshaking.
*/
public void setUseClientMode(boolean clientMode) {
this.client = clientMode;
}
/**
* Returns true if the engine will require client authentication.
* This option is only useful to engines in the server mode.
*/
public boolean isNeedClientAuth() {
return needClientAuth;
}
/**
* Configures the engine to require client authentication.
* This option is only useful for engines in the server mode.
*/
public void setNeedClientAuth(boolean needClientAuth) {
this.needClientAuth = needClientAuth;
}
/**
* Returns true if the engine will request client authentication.
* This option is only useful to engines in the server mode.
*/
public boolean isWantClientAuth() {
return wantClientAuth;
}
/**
* Configures the engine to request client authentication.
* This option is only useful for engines in the server mode.
*/
public void setWantClientAuth(boolean wantClientAuth) {
this.wantClientAuth = wantClientAuth;
}
/**
* Returns the list of cipher suites to be enabled when {@link SSLEngine}
* is initialized.
*
* @return null means 'use {@link SSLEngine}'s default.'
*/
public String[] getEnabledCipherSuites() {
return enabledCipherSuites;
}
/**
* Sets the list of cipher suites to be enabled when {@link SSLEngine}
* is initialized.
*
* @param cipherSuites null means 'use {@link SSLEngine}'s default.'
*/
public void setEnabledCipherSuites(String[] cipherSuites) {
this.enabledCipherSuites = cipherSuites;
}
/**
* Returns the list of protocols to be enabled when {@link SSLEngine}
* is initialized.
*
* @return null means 'use {@link SSLEngine}'s default.'
*/
public String[] getEnabledProtocols() {
return enabledProtocols;
}
/**
* Sets the list of protocols to be enabled when {@link SSLEngine}
* is initialized.
*
* @param protocols null means 'use {@link SSLEngine}'s default.'
*/
public void setEnabledProtocols(String[] protocols) {
this.enabledProtocols = protocols;
}
public void onPreAdd(IoFilterChain parent, String name,
NextFilter nextFilter) throws SSLException {
if (parent.contains(SSLFilter.class)) {
throw new IllegalStateException(
"A filter chain cannot contain more than one SSLFilter.");
}
IoSession session = parent.getSession();
session.setAttribute(NEXT_FILTER, nextFilter);
// Create an SSL handler and start handshake.
SSLHandler handler = new SSLHandler(this, sslContext, session);
session.setAttribute(SSL_HANDLER, handler);
}
public void onPostAdd(IoFilterChain parent, String name,
NextFilter nextFilter) throws SSLException {
SSLHandler handler = getSSLSessionHandler(parent.getSession());
synchronized (handler) {
handler.handshake(nextFilter);
}
handler.flushScheduledEvents();
}
public void onPreRemove(IoFilterChain parent, String name,
NextFilter nextFilter) throws SSLException {
IoSession session = parent.getSession();
stopSSL(session);
session.removeAttribute(NEXT_FILTER);
session.removeAttribute(SSL_HANDLER);
}
// IoFilter impl.
public void sessionClosed(NextFilter nextFilter, IoSession session)
throws SSLException {
SSLHandler handler = getSSLSessionHandler(session);
try {
synchronized (handler) {
if (isSSLStarted(session)) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Closed: "
+ getSSLSessionHandler(session));
}
}
// release resources
handler.destroy();
}
handler.flushScheduledEvents();
} finally {
// notify closed session
nextFilter.sessionClosed(session);
}
}
public void messageReceived(NextFilter nextFilter, IoSession session,
Object message) throws SSLException {
SSLHandler handler = getSSLSessionHandler(session);
synchronized (handler) {
if (!isSSLStarted(session) && handler.isInboundDone()) {
handler.scheduleMessageReceived(nextFilter, message);
} else {
ByteBuffer buf = (ByteBuffer) message;
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Data Read: " + handler + " ("
+ buf + ')');
}
try {
// forward read encrypted data to SSL handler
handler.messageReceived(nextFilter, buf.buf());
// Handle data to be forwarded to application or written to net
handleSSLData(nextFilter, handler);
if (handler.isInboundDone()) {
if (handler.isOutboundDone()) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session,
" SSL Session closed.");
}
handler.destroy();
} else {
initiateClosure(nextFilter, session);
}
if (buf.hasRemaining()) {
// Forward the data received after closure.
handler.scheduleMessageReceived(nextFilter, buf);
}
}
} catch (SSLException ssle) {
if (!handler.isHandshakeComplete()) {
SSLException newSSLE = new SSLHandshakeException(
"SSL handshake failed.");
newSSLE.initCause(ssle);
ssle = newSSLE;
}
throw ssle;
}
}
}
handler.flushScheduledEvents();
}
public void messageSent(NextFilter nextFilter, IoSession session,
Object message) {
if (message instanceof EncryptedBuffer) {
EncryptedBuffer buf = (EncryptedBuffer) message;
buf.release();
nextFilter.messageSent(session, buf.originalBuffer);
} else {
// ignore extra buffers used for handshaking
}
}
public void filterWrite(NextFilter nextFilter, IoSession session,
WriteRequest writeRequest) throws SSLException {
boolean needsFlush = true;
SSLHandler handler = getSSLSessionHandler(session);
synchronized (handler) {
if (!isSSLStarted(session)) {
handler.scheduleFilterWrite(nextFilter,
writeRequest);
}
// Don't encrypt the data if encryption is disabled.
else if (session.containsAttribute(DISABLE_ENCRYPTION_ONCE)) {
// Remove the marker attribute because it is temporary.
session.removeAttribute(DISABLE_ENCRYPTION_ONCE);
handler.scheduleFilterWrite(nextFilter,
writeRequest);
} else {
// Otherwise, encrypt the buffer.
ByteBuffer buf = (ByteBuffer) writeRequest.getMessage();
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Filtered Write: " + handler);
}
if (handler.isWritingEncryptedData()) {
// data already encrypted; simply return buffer
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " already encrypted: "
+ buf);
}
handler.scheduleFilterWrite(nextFilter,
writeRequest);
} else if (handler.isHandshakeComplete()) {
// SSL encrypt
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " encrypt: " + buf);
}
int pos = buf.position();
handler.encrypt(buf.buf());
buf.position(pos);
ByteBuffer encryptedBuffer = new EncryptedBuffer(SSLHandler
.copy(handler.getOutNetBuffer()), buf);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " encrypted buf: "
+ encryptedBuffer);
}
handler.scheduleFilterWrite(nextFilter,
new WriteRequest(encryptedBuffer, writeRequest
.getFuture()));
} else {
if (!session.isConnected()) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session,
" Write request on closed session.");
}
} else {
if (SessionLog.isDebugEnabled(session)) {
SessionLog
.debug(session,
" Handshaking is not complete yet. Buffering write request.");
}
handler.schedulePreHandshakeWriteRequest(nextFilter,
writeRequest);
}
needsFlush = false;
}
}
}
if (needsFlush) {
handler.flushScheduledEvents();
}
}
public void filterClose(final NextFilter nextFilter, final IoSession session)
throws SSLException {
SSLHandler handler = getSSLSessionHandler0(session);
if (handler == null) {
// The connection might already have closed, or
// SSL might have not started yet.
nextFilter.filterClose(session);
return;
}
WriteFuture future = null;
try {
synchronized (handler) {
if (isSSLStarted(session)) {
future = initiateClosure(nextFilter, session);
future.addListener(new IoFutureListener() {
public void operationComplete(IoFuture future) {
nextFilter.filterClose(session);
}
});
}
}
handler.flushScheduledEvents();
} finally {
if (future == null) {
nextFilter.filterClose(session);
}
}
}
private WriteFuture initiateClosure(NextFilter nextFilter, IoSession session)
throws SSLException {
SSLHandler handler = getSSLSessionHandler(session);
// if already shut down
if (!handler.closeOutbound()) {
return DefaultWriteFuture.newNotWrittenFuture(session);
}
// there might be data to write out here?
WriteFuture future = handler.writeNetBuffer(nextFilter);
if (handler.isInboundDone()) {
handler.destroy();
}
if (session.containsAttribute(USE_NOTIFICATION)) {
handler.scheduleMessageReceived(nextFilter, SESSION_UNSECURED);
}
return future;
}
// Utiliities
private void handleSSLData(NextFilter nextFilter, SSLHandler handler)
throws SSLException {
// Flush any buffered write requests occurred before handshaking.
if (handler.isHandshakeComplete()) {
handler.flushPreHandshakeEvents();
}
// Write encrypted data to be written (if any)
handler.writeNetBuffer(nextFilter);
// handle app. data read (if any)
handleAppDataRead(nextFilter, handler);
}
private void handleAppDataRead(NextFilter nextFilter, SSLHandler handler) {
IoSession session = handler.getSession();
handler.getAppBuffer().flip();
if (!handler.getAppBuffer().hasRemaining()) {
handler.getAppBuffer().clear();
return;
}
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " appBuffer: " + handler.getAppBuffer());
}
// forward read app data
ByteBuffer readBuffer = SSLHandler.copy(handler.getAppBuffer());
handler.getAppBuffer().clear();
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " app data read: " + readBuffer + " ("
+ readBuffer.getHexDump() + ')');
}
handler.scheduleMessageReceived(nextFilter, readBuffer);
}
private SSLHandler getSSLSessionHandler(IoSession session) {
SSLHandler handler = getSSLSessionHandler0(session);
if (handler == null) {
throw new IllegalStateException();
}
if (handler.getParent() != this) {
throw new IllegalArgumentException("Not managed by this filter.");
}
return handler;
}
private SSLHandler getSSLSessionHandler0(IoSession session) {
return (SSLHandler) session.getAttribute(SSL_HANDLER);
}
/**
* A message that is sent from {@link SSLFilter} when the connection became
* secure or is not secure anymore.
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 587373 $, $Date: 2007-10-23 11:54:05 +0900 (Tue, 23 Oct 2007) $
*/
public static class SSLFilterMessage {
private final String name;
private SSLFilterMessage(String name) {
this.name = name;
}
public String toString() {
return name;
}
}
private static class EncryptedBuffer extends ByteBufferProxy {
private final ByteBuffer originalBuffer;
private EncryptedBuffer(ByteBuffer buf, ByteBuffer originalBuffer) {
super(buf);
this.originalBuffer = originalBuffer;
}
}
}
mina-1.1.7.dfsg/filter-ssl/src/main/java/org/apache/mina/filter/support/ 0000755 0001750 0001750 00000000000 11044712500 025731 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/main/java/org/apache/mina/filter/support/SSLByteBufferPool.java 0000644 0001750 0001750 00000013336 11002320015 032041 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.filter.support;
import java.nio.ByteBuffer;
import javax.net.ssl.SSLEngine;
import org.apache.mina.util.Stack;
/**
* Simple ByteBuffer pool used by SSLHandler.
* ByteBuffers are by default allocated as direct byte buffers. To use non-direct
* ByteBuffers, set system property mina.sslfilter.directbuffer to false.
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
*/
class SSLByteBufferPool {
private static final int PACKET_BUFFER_INDEX = 0;
private static final int APPLICATION_BUFFER_INDEX = 1;
private static boolean initiated = false;
private static final String DIRECT_MEMORY_PROP = "mina.sslfilter.directbuffer";
private static boolean useDirectAllocatedBuffers = true;
private static int packetBufferSize;
private static int appBufferSize;
private static int[] bufferStackSizes;
private static final Stack[] bufferStacks = new Stack[] { new Stack(),
new Stack(), };
/**
* Initiate buffer pool and buffer sizes from SSLEngine session.
*
* @param sslEngine SSLEngine
*/
static synchronized void initiate(SSLEngine sslEngine) {
if (!initiated) {
// Use direct allocated memory or not?
String prop = System.getProperty(DIRECT_MEMORY_PROP);
if (prop != null) {
useDirectAllocatedBuffers = Boolean
.getBoolean(DIRECT_MEMORY_PROP);
}
// init buffer sizes from SSLEngine
packetBufferSize = sslEngine.getSession().getPacketBufferSize();
// application buffer size has been doubled because SSLEngine
// returns BUFFER_OVERFLOW even if there is enough room for the buffer.
// So for now we use a size double the packet size as a workaround.
appBufferSize = packetBufferSize * 2;
initiateBufferStacks();
initiated = true;
}
}
/**
* Get bytebuffer with size the size of the largest SSL/TLS packet that may occur
* (as defined by SSLSession).
*/
static ByteBuffer getPacketBuffer() {
if (!initiated) {
throw new IllegalStateException("Not initialized");
}
return allocate(PACKET_BUFFER_INDEX);
}
/**
* Get ByteBuffer with the size of the largest application buffer that may occur
* (as defined by SSLSession).
*/
static ByteBuffer getApplicationBuffer() {
if (!initiated) {
throw new IllegalStateException("Not initialized");
}
return allocate(APPLICATION_BUFFER_INDEX);
}
/**
* Allocate or get the buffer which is capable of the specified size.
*/
private static ByteBuffer allocate(int idx) {
Stack stack = bufferStacks[idx];
ByteBuffer buf;
synchronized (stack) {
buf = (ByteBuffer) stack.pop();
if (buf == null) {
buf = createBuffer(bufferStackSizes[idx]);
}
}
buf.clear();
return buf;
}
/**
* Releases the specified buffer to buffer pool.
*/
public static void release(ByteBuffer buf) {
// Sweep buffer for security.
org.apache.mina.common.ByteBuffer.wrap(buf).sweep().release();
int stackIndex = getBufferStackIndex(buf.capacity());
if (stackIndex >= PACKET_BUFFER_INDEX) {
Stack stack = bufferStacks[getBufferStackIndex(buf.capacity())];
synchronized (stack) {
stack.push(buf);
}
}
}
/**
* Expand size of provided buffer
* @param buf buffer to be expande
* @param newCapacity new capacity
*/
public static ByteBuffer expandBuffer(ByteBuffer buf, int newCapacity) {
ByteBuffer newBuf = createBuffer(newCapacity);
buf.flip();
newBuf.put(buf);
release(buf);
return newBuf;
}
private static void initiateBufferStacks() {
bufferStackSizes = new int[2];
bufferStackSizes[PACKET_BUFFER_INDEX] = packetBufferSize;
bufferStackSizes[APPLICATION_BUFFER_INDEX] = appBufferSize;
}
private static int getBufferStackIndex(int size) {
if (size == packetBufferSize)
return PACKET_BUFFER_INDEX;
if (size == appBufferSize)
return APPLICATION_BUFFER_INDEX;
return -1; // not reused
}
private static ByteBuffer createBuffer(int capacity) {
if (useDirectAllocatedBuffers) {
try {
return ByteBuffer.allocateDirect(capacity);
} catch (OutOfMemoryError e) {
useDirectAllocatedBuffers = false;
System.err
.println("OutOfMemoryError: No more direct buffers available; trying heap buffer instead");
}
}
return ByteBuffer.allocate(capacity);
}
}
mina-1.1.7.dfsg/filter-ssl/src/main/java/org/apache/mina/filter/support/package.html 0000644 0001750 0001750 00000000257 11002320015 030204 0 ustar drazzib drazzib
Internal classes used by org.apache.mina.filter package.
mina-1.1.7.dfsg/filter-ssl/src/main/java/org/apache/mina/filter/support/SSLHandler.java 0000644 0001750 0001750 00000062257 11002320015 030535 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.filter.support;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSession;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.WriteFuture;
import org.apache.mina.common.IoFilter.NextFilter;
import org.apache.mina.common.IoFilter.WriteRequest;
import org.apache.mina.common.support.DefaultWriteFuture;
import org.apache.mina.filter.SSLFilter;
import org.apache.mina.util.SessionLog;
/**
* A helper class using the SSLEngine API to decrypt/encrypt data.
*
* Each connection has a SSLEngine that is used through the lifetime of the connection.
* We allocate byte buffers for use as the outbound and inbound network buffers.
* These buffers handle all of the intermediary data for the SSL connection. To make things easy,
* we'll require outNetBuffer be completely flushed before trying to wrap any more data.
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 561232 $, $Date: 2007-07-31 14:19:37 +0900 (Tue, 31 Jul 2007) $
*/
public class SSLHandler {
private final SSLFilter parent;
private final SSLContext ctx;
private final IoSession session;
private final Queue preHandshakeEventQueue = new LinkedList();
private final Queue filterWriteEventQueue = new ConcurrentLinkedQueue();
private final Queue messageReceivedEventQueue = new ConcurrentLinkedQueue();
private SSLEngine sslEngine;
/**
* Encrypted data from the net
*/
private ByteBuffer inNetBuffer;
/**
* Encrypted data to be written to the net
*/
private ByteBuffer outNetBuffer;
/**
* Applicaton cleartext data to be read by application
*/
private ByteBuffer appBuffer;
/**
* Empty buffer used during initial handshake and close operations
*/
private final ByteBuffer hsBB = ByteBuffer.allocate(0);
/**
* Handshake status
*/
private SSLEngineResult.HandshakeStatus handshakeStatus;
private boolean initialHandshakeComplete;
/**
* Handshake complete?
*/
private boolean handshakeComplete;
private boolean writingEncryptedData;
/**
* Constuctor.
*
* @param sslc
* @throws SSLException
*/
public SSLHandler(SSLFilter parent, SSLContext sslc, IoSession session)
throws SSLException {
this.parent = parent;
this.session = session;
this.ctx = sslc;
init();
}
public void init() throws SSLException {
if (sslEngine != null) {
return;
}
sslEngine = ctx.createSSLEngine();
sslEngine.setUseClientMode(parent.isUseClientMode());
if (parent.isWantClientAuth()) {
sslEngine.setWantClientAuth(true);
}
if (parent.isNeedClientAuth()) {
sslEngine.setNeedClientAuth(true);
}
if (parent.getEnabledCipherSuites() != null) {
sslEngine.setEnabledCipherSuites(parent.getEnabledCipherSuites());
}
if (parent.getEnabledProtocols() != null) {
sslEngine.setEnabledProtocols(parent.getEnabledProtocols());
}
sslEngine.beginHandshake();
handshakeStatus = sslEngine.getHandshakeStatus();//SSLEngineResult.HandshakeStatus.NEED_UNWRAP;
handshakeComplete = false;
initialHandshakeComplete = false;
SSLByteBufferPool.initiate(sslEngine);
appBuffer = SSLByteBufferPool.getApplicationBuffer();
inNetBuffer = SSLByteBufferPool.getPacketBuffer();
outNetBuffer = SSLByteBufferPool.getPacketBuffer();
outNetBuffer.position(0);
outNetBuffer.limit(0);
writingEncryptedData = false;
}
/**
* Release allocated ByteBuffers.
*/
public void destroy() {
if (sslEngine == null) {
return;
}
// Close inbound and flush all remaining data if available.
try {
sslEngine.closeInbound();
} catch (SSLException e) {
SessionLog.debug(session,
"Unexpected exception from SSLEngine.closeInbound().", e);
}
try {
do {
outNetBuffer.clear();
} while (sslEngine.wrap(hsBB, outNetBuffer).bytesProduced() > 0);
} catch (SSLException e) {
SessionLog.debug(session,
"Unexpected exception from SSLEngine.wrap().", e);
}
sslEngine.closeOutbound();
sslEngine = null;
SSLByteBufferPool.release(appBuffer);
SSLByteBufferPool.release(inNetBuffer);
SSLByteBufferPool.release(outNetBuffer);
preHandshakeEventQueue.clear();
}
public SSLFilter getParent() {
return parent;
}
public IoSession getSession() {
return session;
}
/**
* Check we are writing encrypted data.
*/
public boolean isWritingEncryptedData() {
return writingEncryptedData;
}
/**
* Check if handshake is completed.
*/
public boolean isHandshakeComplete() {
return handshakeComplete;
}
public boolean isInboundDone() {
return sslEngine == null || sslEngine.isInboundDone();
}
public boolean isOutboundDone() {
return sslEngine == null || sslEngine.isOutboundDone();
}
/**
* Check if there is any need to complete handshake.
*/
public boolean needToCompleteHandshake() {
return (handshakeStatus == SSLEngineResult.HandshakeStatus.NEED_WRAP && !isInboundDone());
}
public void schedulePreHandshakeWriteRequest(NextFilter nextFilter,
WriteRequest writeRequest) {
preHandshakeEventQueue.offer(new Event(EventType.FILTER_WRITE,
nextFilter, writeRequest));
}
public void flushPreHandshakeEvents() throws SSLException {
Event scheduledWrite;
while ((scheduledWrite = preHandshakeEventQueue.poll()) != null) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Flushing buffered write request: "
+ scheduledWrite.data);
}
parent.filterWrite(scheduledWrite.nextFilter, session,
(WriteRequest) scheduledWrite.data);
}
}
public void scheduleFilterWrite(NextFilter nextFilter,
WriteRequest writeRequest) {
filterWriteEventQueue.offer(new Event(EventType.FILTER_WRITE,
nextFilter, writeRequest));
}
public void scheduleMessageReceived(NextFilter nextFilter,
Object message) {
messageReceivedEventQueue.offer(new Event(EventType.RECEIVED, nextFilter,
message));
}
public void flushScheduledEvents() {
// Fire events only when no lock is hold for this handler.
if (Thread.holdsLock(this)) {
return;
}
Event e;
// We need synchronization here inevitably because filterWrite can be
// called simultaneously and cause 'bad record MAC' integrity error.
synchronized (this) {
while ((e = filterWriteEventQueue.poll()) != null) {
e.nextFilter.filterWrite(session, (WriteRequest) e.data);
}
}
while ((e = messageReceivedEventQueue.poll()) != null) {
e.nextFilter.messageReceived(session, e.data);
}
}
/**
* Call when data read from net. Will perform inial hanshake or decrypt provided
* Buffer.
* Decrytpted data reurned by getAppBuffer(), if any.
*
* @param buf buffer to decrypt
* @throws SSLException on errors
*/
public void messageReceived(NextFilter nextFilter, ByteBuffer buf)
throws SSLException {
if (buf.limit() > inNetBuffer.remaining()) {
// We have to expand inNetBuffer
inNetBuffer = SSLByteBufferPool.expandBuffer(inNetBuffer,
inNetBuffer.capacity() + (buf.limit() * 2));
// We also expand app. buffer (twice the size of in net. buffer)
appBuffer = SSLByteBufferPool.expandBuffer(appBuffer, inNetBuffer
.capacity() * 2);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " expanded inNetBuffer:"
+ inNetBuffer);
SessionLog.debug(session, " expanded appBuffer:" + appBuffer);
}
}
// append buf to inNetBuffer
inNetBuffer.put(buf);
if (!handshakeComplete) {
handshake(nextFilter);
} else {
decrypt(nextFilter);
}
if (isInboundDone()) {
// Rewind the MINA buffer if not all data is processed and inbound is finished.
buf.position(buf.position() - inNetBuffer.position());
inNetBuffer.clear();
}
}
/**
* Get decrypted application data.
*
* @return buffer with data
*/
public ByteBuffer getAppBuffer() {
return appBuffer;
}
/**
* Get encrypted data to be sent.
*
* @return buffer with data
*/
public ByteBuffer getOutNetBuffer() {
return outNetBuffer;
}
/**
* Encrypt provided buffer. Encytpted data reurned by getOutNetBuffer().
*
* @param src data to encrypt
* @throws SSLException on errors
*/
public void encrypt(ByteBuffer src) throws SSLException {
if (!handshakeComplete) {
throw new IllegalStateException();
}
// The data buffer is (must be) empty, we can reuse the entire
// buffer.
outNetBuffer.clear();
// Loop until there is no more data in src
while (src.hasRemaining()) {
if (src.remaining() > ((outNetBuffer.capacity() - outNetBuffer
.position()) / 2)) {
// We have to expand outNetBuffer
// Note: there is no way to know the exact size required, but enrypted data
// shouln't need to be larger than twice the source data size?
outNetBuffer = SSLByteBufferPool.expandBuffer(outNetBuffer, src
.capacity() * 2);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " expanded outNetBuffer:"
+ outNetBuffer);
}
}
SSLEngineResult result = sslEngine.wrap(src, outNetBuffer);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Wrap res:" + result);
}
if (result.getStatus() == SSLEngineResult.Status.OK) {
if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK) {
doTasks();
}
} else {
throw new SSLException("SSLEngine error during encrypt: "
+ result.getStatus() + " src: " + src
+ "outNetBuffer: " + outNetBuffer);
}
}
outNetBuffer.flip();
}
/**
* Start SSL shutdown process.
*
* @return true if shutdown process is started.
* false if shutdown process is already finished.
*
* @throws SSLException on errors
*/
public boolean closeOutbound() throws SSLException {
if (sslEngine == null || sslEngine.isOutboundDone()) {
return false;
}
sslEngine.closeOutbound();
// By RFC 2616, we can "fire and forget" our close_notify
// message, so that's what we'll do here.
outNetBuffer.clear();
SSLEngineResult result = sslEngine.wrap(hsBB, outNetBuffer);
if (result.getStatus() != SSLEngineResult.Status.CLOSED) {
throw new SSLException("Improper close state: " + result);
}
outNetBuffer.flip();
return true;
}
/**
* Decrypt in net buffer. Result is stored in app buffer.
*
* @throws SSLException
*/
private void decrypt(NextFilter nextFilter) throws SSLException {
if (!handshakeComplete) {
throw new IllegalStateException();
}
unwrap(nextFilter);
}
/**
* @param status
* @throws SSLException
*/
private void checkStatus(SSLEngineResult res)
throws SSLException {
SSLEngineResult.Status status = res.getStatus();
/*
* The status may be:
* OK - Normal operation
* OVERFLOW - Should never happen since the application buffer is
* sized to hold the maximum packet size.
* UNDERFLOW - Need to read more data from the socket. It's normal.
* CLOSED - The other peer closed the socket. Also normal.
*/
if (status != SSLEngineResult.Status.OK
&& status != SSLEngineResult.Status.CLOSED
&& status != SSLEngineResult.Status.BUFFER_UNDERFLOW) {
throw new SSLException("SSLEngine error during decrypt: " + status
+ " inNetBuffer: " + inNetBuffer + "appBuffer: "
+ appBuffer);
}
}
/**
* Perform any handshaking processing.
*/
public void handshake(NextFilter nextFilter) throws SSLException {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " doHandshake()");
}
for (;;) {
if (handshakeStatus == SSLEngineResult.HandshakeStatus.FINISHED) {
session.setAttribute(SSLFilter.SSL_SESSION, sslEngine
.getSession());
if (SessionLog.isDebugEnabled(session)) {
SSLSession sslSession = sslEngine.getSession();
SessionLog.debug(session,
" handshakeStatus=FINISHED");
SessionLog.debug(session, " sslSession CipherSuite used "
+ sslSession.getCipherSuite());
}
handshakeComplete = true;
if (!initialHandshakeComplete
&& session.containsAttribute(SSLFilter.USE_NOTIFICATION)) {
// SESSION_SECURED is fired only when it's the first handshake.
// (i.e. renegotiation shouldn't trigger SESSION_SECURED.)
initialHandshakeComplete = true;
scheduleMessageReceived(nextFilter,
SSLFilter.SESSION_SECURED);
}
break;
} else if (handshakeStatus == SSLEngineResult.HandshakeStatus.NEED_TASK) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session,
" handshakeStatus=NEED_TASK");
}
handshakeStatus = doTasks();
} else if (handshakeStatus == SSLEngineResult.HandshakeStatus.NEED_UNWRAP) {
// we need more data read
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session,
" handshakeStatus=NEED_UNWRAP");
}
SSLEngineResult.Status status = unwrapHandshake(nextFilter);
if (status == SSLEngineResult.Status.BUFFER_UNDERFLOW
|| isInboundDone()) {
// We need more data or the session is closed
break;
}
} else if (handshakeStatus == SSLEngineResult.HandshakeStatus.NEED_WRAP) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session,
" handshakeStatus=NEED_WRAP");
}
// First make sure that the out buffer is completely empty. Since we
// cannot call wrap with data left on the buffer
if (outNetBuffer.hasRemaining()) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog
.debug(session, " Still data in out buffer!");
}
break;
}
outNetBuffer.clear();
SSLEngineResult result = sslEngine.wrap(hsBB, outNetBuffer);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Wrap res:" + result);
}
outNetBuffer.flip();
handshakeStatus = result.getHandshakeStatus();
writeNetBuffer(nextFilter);
} else {
throw new IllegalStateException("Invalid Handshaking State"
+ handshakeStatus);
}
}
}
public WriteFuture writeNetBuffer(NextFilter nextFilter)
throws SSLException {
// Check if any net data needed to be writen
if (!getOutNetBuffer().hasRemaining()) {
// no; bail out
return DefaultWriteFuture.newNotWrittenFuture(session);
}
// set flag that we are writing encrypted data
// (used in SSLFilter.filterWrite())
writingEncryptedData = true;
// write net data
WriteFuture writeFuture = null;
try {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " write outNetBuffer: "
+ getOutNetBuffer());
}
org.apache.mina.common.ByteBuffer writeBuffer = copy(getOutNetBuffer());
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " session write: " + writeBuffer);
}
//debug("outNetBuffer (after copy): {0}", sslHandler.getOutNetBuffer());
writeFuture = new DefaultWriteFuture(session);
parent.filterWrite(nextFilter, session, new WriteRequest(
writeBuffer, writeFuture));
// loop while more writes required to complete handshake
while (needToCompleteHandshake()) {
try {
handshake(nextFilter);
} catch (SSLException ssle) {
SSLException newSSLE = new SSLHandshakeException(
"SSL handshake failed.");
newSSLE.initCause(ssle);
throw newSSLE;
}
if (getOutNetBuffer().hasRemaining()) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " write outNetBuffer2: "
+ getOutNetBuffer());
}
org.apache.mina.common.ByteBuffer writeBuffer2 = copy(getOutNetBuffer());
writeFuture = new DefaultWriteFuture(session);
parent.filterWrite(nextFilter, session, new WriteRequest(
writeBuffer2, writeFuture));
}
}
} finally {
writingEncryptedData = false;
}
return writeFuture;
}
private void unwrap(NextFilter nextFilter) throws SSLException {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " unwrap()");
}
// Prepare the net data for reading.
inNetBuffer.flip();
SSLEngineResult res = unwrap0();
// prepare to be written again
inNetBuffer.compact();
checkStatus(res);
renegotiateIfNeeded(nextFilter, res);
}
private SSLEngineResult.Status unwrapHandshake(NextFilter nextFilter) throws SSLException {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " unwrapHandshake()");
}
// Prepare the net data for reading.
inNetBuffer.flip();
SSLEngineResult res = unwrap0();
handshakeStatus = res.getHandshakeStatus();
checkStatus(res);
// If handshake finished, no data was produced, and the status is still ok,
// try to unwrap more
if (handshakeStatus == SSLEngineResult.HandshakeStatus.FINISHED
&& res.getStatus() == SSLEngineResult.Status.OK
&& inNetBuffer.hasRemaining()) {
res = unwrap0();
// prepare to be written again
inNetBuffer.compact();
renegotiateIfNeeded(nextFilter, res);
} else {
// prepare to be written again
inNetBuffer.compact();
}
return res.getStatus();
}
private void renegotiateIfNeeded(NextFilter nextFilter, SSLEngineResult res)
throws SSLException {
if (res.getStatus() != SSLEngineResult.Status.CLOSED
&& res.getStatus() != SSLEngineResult.Status.BUFFER_UNDERFLOW
&& res.getHandshakeStatus() != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
// Renegotiation required.
SessionLog.debug(session, " Renegotiating...");
handshakeComplete = false;
handshakeStatus = res.getHandshakeStatus();
handshake(nextFilter);
}
}
private SSLEngineResult unwrap0() throws SSLException {
SSLEngineResult res;
do {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " inNetBuffer: " + inNetBuffer);
SessionLog.debug(session, " appBuffer: " + appBuffer);
}
res = sslEngine.unwrap(inNetBuffer, appBuffer);
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " Unwrap res:" + res);
}
} while (res.getStatus() == SSLEngineResult.Status.OK
&& (handshakeComplete && res.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING
|| res.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_UNWRAP));
return res;
}
/**
* Do all the outstanding handshake tasks in the current Thread.
*/
private SSLEngineResult.HandshakeStatus doTasks() {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " doTasks()");
}
/*
* We could run this in a separate thread, but I don't see the need
* for this when used from SSLFilter. Use thread filters in MINA instead?
*/
Runnable runnable;
while ((runnable = sslEngine.getDelegatedTask()) != null) {
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " doTask: " + runnable);
}
runnable.run();
}
if (SessionLog.isDebugEnabled(session)) {
SessionLog.debug(session, " doTasks(): "
+ sslEngine.getHandshakeStatus());
}
return sslEngine.getHandshakeStatus();
}
/**
* Creates a new Mina byte buffer that is a deep copy of the remaining bytes
* in the given buffer (between index buf.position() and buf.limit())
*
* @param src the buffer to copy
* @return the new buffer, ready to read from
*/
public static org.apache.mina.common.ByteBuffer copy(java.nio.ByteBuffer src) {
org.apache.mina.common.ByteBuffer copy = org.apache.mina.common.ByteBuffer
.allocate(src.remaining());
copy.put(src);
copy.flip();
return copy;
}
private static class EventType {
public static final EventType RECEIVED = new EventType("RECEIVED");
public static final EventType FILTER_WRITE = new EventType(
"FILTER_WRITE");
private final String value;
private EventType(String value) {
this.value = value;
}
public String toString() {
return value;
}
}
private static class Event {
private final EventType type;
private final NextFilter nextFilter;
private final Object data;
Event(EventType type, NextFilter nextFilter, Object data) {
this.type = type;
this.nextFilter = nextFilter;
this.data = data;
}
public Object getData() {
return data;
}
public NextFilter getNextFilter() {
return nextFilter;
}
public EventType getType() {
return type;
}
}
}
mina-1.1.7.dfsg/filter-ssl/src/test/ 0000755 0001750 0001750 00000000000 11002320014 017073 5 ustar drazzib drazzib mina-1.1.7.dfsg/filter-ssl/src/test/java/ 0000755 0001750 0001750 00000000000 11002320014 020014 5 ustar drazzib drazzib mina-1.1.7.dfsg/pom.xml 0000644 0001750 0001750 00000013337 11002320032 014565 0 ustar drazzib drazzib
4.0.0org.apacheapache3Apache MINA Projecthttp://mina.apache.org/org.apache.mina1.1.7buildApache MINA Root Build POMpomhttp://mina.apache.org/2004jirahttp://issues.apache.org/jira/browse/DIRMINAscm:svn:http://svn.apache.org/repos/asf/mina/tags/1.1.7http://svn.apache.org/viewvc/mina/tags/1.1.7scm:svn:https://svn.apache.org/repos/asf/mina/tags/1.1.7apache.websitesscp://people.apache.org/www/mina.apache.org/report/1.1/mail
dev@mina.apache.org
MINA (Multipurpose Infrastructure for Network Applications) is a
network application framework which helps users develop high
performance and highly scalable network applications easily.
Apache 2.0 Licensehttp://www.apache.org/licenses/LICENSE-2.0repojunitjunit3.8.1testcorefilter-sslfilter-codec-nettyfilter-compressionintegration-springintegration-jmxexampleorg.apache.maven.pluginsmaven-compiler-pluginUTF-81.51.5truetruetruemaven-surefire-plugin**/Abstract***/DatagramBindTest.java**/VmPipeTrafficControlTest.java**/*RegressionTest*org.apache.maven.pluginsmaven-source-pluginattach-sourcesjarmaven-assembly-pluginrelease.xmlmina-${pom.version}falsegnumaven-release-plugin
https://svn.apache.org/repos/asf/mina/tags
org.apache.maven.pluginsmaven-javadoc-pluginfalsetruetrueUTF-8UTF-8Apache MINA ${project.version} API DocumentationApache MINA ${project.version} API DocumentationUTF-8*.support:*.example.*
http://java.sun.com/j2se/1.5.0/docs/api/
http://www.slf4j.org/api/
http://static.springframework.org/spring/docs/2.0.x/api/
en_USorg.apache.maven.pluginsmaven-jxr-pluginfalsetrueUTF-8UTF-8Apache MINA ${project.version} Cross ReferenceApache MINA ${project.version} Cross Reference
mina-1.1.7.dfsg/core/ 0000755 0001750 0001750 00000000000 11044712500 014204 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/pom.xml 0000644 0001750 0001750 00000002066 11002320031 015511 0 ustar drazzib drazzib
4.0.0org.apache.minabuild1.1.7mina-coreApache MINA Core APIjarorg.slf4jslf4j-api1.4.3compileorg.slf4jslf4j-simple1.4.3testeasymockeasymock1.2_Java1.3test
mina-1.1.7.dfsg/core/src/ 0000755 0001750 0001750 00000000000 11002320030 014756 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/docs/ 0000755 0001750 0001750 00000000000 11044712500 015723 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/ 0000755 0001750 0001750 00000000000 11002320030 015702 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/resources/ 0000755 0001750 0001750 00000000000 11002320030 017714 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/resources/META-INF/ 0000755 0001750 0001750 00000000000 11044712500 021071 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/resources/META-INF/LICENSE.jzlib.txt 0000644 0001750 0001750 00000003161 11002320030 024011 0 ustar drazzib drazzib JZlib 0.0.* were released under the GNU LGPL license. Later, we have switched
over to a BSD-style license.
------------------------------------------------------------------------------
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mina-1.1.7.dfsg/core/src/main/resources/META-INF/LICENSE.txt 0000644 0001750 0001750 00000024157 11002320030 022710 0 ustar drazzib drazzib Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
mina-1.1.7.dfsg/core/src/main/resources/META-INF/LICENSE.slf4j.txt 0000644 0001750 0001750 00000002755 11002320030 023731 0 ustar drazzib drazzib Copyright (c) 2004-2005 SLF4J.ORG
Copyright (c) 2004-2005 QOS.ch
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, provided that the above
copyright notice(s) and this permission notice appear in all copies of
the Software and that both the above copyright notice(s) and this
permission notice appear in supporting documentation.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Except as contained in this notice, the name of a copyright holder
shall not be used in advertising or otherwise to promote the sale, use
or other dealings in this Software without prior written authorization
of the copyright holder.
mina-1.1.7.dfsg/core/src/main/resources/META-INF/NOTICE.txt 0000644 0001750 0001750 00000001517 11002320030 022602 0 ustar drazzib drazzib Apache MINA
Copyright 2007 The Apache Software Foundation.
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
Message logging is provided by the SLF4J library package,
which is open source software, written by Ceki Gülcü, and
copyright by SLF4J.ORG and QOS.ch. The original software is
available from
http://www.slf4j.org/
Data compression support is provided by the JZLib library package,
which is open source software, written by JCraft, and copyright
by JCraft. The original software is available from
http://www.jcraft.com/jzlib/
Spring framework is provided by the Spring framework library
package, which is open source software, written by Rod Johnson
et al, and copyright by Springframework.org. The original
software is available from
http://www.springframework.org/
mina-1.1.7.dfsg/core/src/main/resources/META-INF/LICENSE.springframework.txt 0000644 0001750 0001750 00000024157 11002320030 026127 0 ustar drazzib drazzib Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
mina-1.1.7.dfsg/core/src/main/java/ 0000755 0001750 0001750 00000000000 11002320020 016622 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/java/org/ 0000755 0001750 0001750 00000000000 11002320020 017411 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/java/org/apache/ 0000755 0001750 0001750 00000000000 11002320020 020632 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/ 0000755 0001750 0001750 00000000000 11002320030 021557 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/management/ 0000755 0001750 0001750 00000000000 11044712500 023710 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/management/StatCollector.java 0000644 0001750 0001750 00000026237 11002320023 027334 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.management;
import java.net.SocketAddress;
import java.util.Iterator;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoService;
import org.apache.mina.common.IoServiceConfig;
import org.apache.mina.common.IoServiceListener;
import org.apache.mina.common.IoSession;
/**
* Collects statistics of an {@link IoService}. It's polling all the sessions of a given
* IoService. It's attaching a {@link IoSessionStat} object to all the sessions polled
* and filling the throughput values.
*
* Usage :
*
* IoService service = ...
* StatCollector collector = new StatCollector( service );
* collector.start();
*
*
* By default the {@link StatCollector} is polling the sessions every 5 seconds. You can
* give a different polling time using a second constructor.
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
*/
public class StatCollector {
/**
* The session attribute key for {@link IoSessionStat}.
*/
public static final String KEY = StatCollector.class.getName() + ".stat";
/**
* @noinspection StaticNonFinalField
*/
private static volatile int nextId = 0;
private final int id = nextId++;
private final Object calcLock = new Object();
private final IoService service;
private Worker worker;
private int pollingInterval = 5000;
private Queue polledSessions;
// resume of session stats, for simplifying acces to the statistics
private AtomicLong totalProcessedSessions = new AtomicLong();
private float msgWrittenThroughput = 0f;
private float msgReadThroughput = 0f;
private float bytesWrittenThroughput = 0f;
private float bytesReadThroughput = 0f;
private final IoServiceListener serviceListener = new IoServiceListener() {
public void serviceActivated(IoService service,
SocketAddress serviceAddress, IoHandler handler,
IoServiceConfig config) {
}
public void serviceDeactivated(IoService service,
SocketAddress serviceAddress, IoHandler handler,
IoServiceConfig config) {
}
public void sessionCreated(IoSession session) {
addSession(session);
}
public void sessionDestroyed(IoSession session) {
removeSession(session);
}
};
/**
* Create a stat collector for the given service with a default polling time of 5 seconds.
* @param service the IoService to inspect
*/
public StatCollector(IoService service) {
this(service, 5000);
}
/**
* create a stat collector for the given given service
* @param service the IoService to inspect
* @param pollingInterval milliseconds
*/
public StatCollector(IoService service, int pollingInterval) {
this.service = service;
this.pollingInterval = pollingInterval;
}
/**
* Start collecting stats for the {@link IoSession} of the service.
* New sessions or destroyed will be automaticly added or removed.
*/
public void start() {
synchronized (this) {
if (worker != null && worker.isAlive())
throw new RuntimeException("Stat collecting already started");
// add all current sessions
polledSessions = new ConcurrentLinkedQueue();
for (Iterator iter = service
.getManagedServiceAddresses().iterator(); iter.hasNext();) {
SocketAddress element = iter.next();
for (Iterator iter2 = service.getManagedSessions(
element).iterator(); iter2.hasNext();) {
addSession(iter2.next());
}
}
// listen for new ones
service.addListener(serviceListener);
// start polling
worker = new Worker();
worker.start();
}
}
/**
* Stop collecting stats. all the {@link IoSessionStat} object will be removed of the
* polled session attachements.
*/
public void stop() {
synchronized (this) {
if (worker == null) {
return;
}
service.removeListener(serviceListener);
// stop worker
worker.stop = true;
worker.interrupt();
while (worker.isAlive()) {
try {
worker.join();
} catch (InterruptedException e) {
//ignore since this is shutdown time
}
}
for (Iterator iter = polledSessions.iterator(); iter.hasNext();) {
IoSession session = (IoSession) iter.next();
session.removeAttribute(KEY);
}
polledSessions.clear();
worker = null;
}
}
/**
* is the stat collector started and polling the {@link IoSession} of the {@link IoService}
* @return true if started
*/
public boolean isRunning() {
synchronized (this) {
return worker != null && worker.stop != true;
}
}
private void addSession(IoSession session) {
IoSessionStat sessionStats = new IoSessionStat();
session.setAttribute(KEY, sessionStats);
totalProcessedSessions.incrementAndGet();
polledSessions.add(session);
}
private void removeSession(IoSession session) {
// remove the session from the list of polled sessions
polledSessions.remove(session);
// add the bytes processed between last polling and session closing
// prevent non seen byte with non-connected protocols like HTTP and datagrams
IoSessionStat sessStat = (IoSessionStat) session.getAttribute(KEY);
// computing with time between polling and closing
long currentTime = System.currentTimeMillis();
synchronized (calcLock) {
bytesReadThroughput += (session.getReadBytes() - sessStat.lastByteRead)
/ ((currentTime - sessStat.lastPollingTime) / 1000f);
bytesWrittenThroughput += (session.getWrittenBytes() - sessStat.lastByteWrite)
/ ((currentTime - sessStat.lastPollingTime) / 1000f);
msgReadThroughput += (session.getReadMessages() - sessStat.lastMessageRead)
/ ((currentTime - sessStat.lastPollingTime) / 1000f);
msgWrittenThroughput += (session.getWrittenMessages() - sessStat.lastMessageWrite)
/ ((currentTime - sessStat.lastPollingTime) / 1000f);
}
session.removeAttribute(KEY);
}
/**
* total number of sessions processed by the stat collector
* @return number of sessions
*/
public long getTotalProcessedSessions() {
return totalProcessedSessions.get();
}
public float getBytesReadThroughput() {
return bytesReadThroughput;
}
public float getBytesWrittenThroughput() {
return bytesWrittenThroughput;
}
public float getMsgReadThroughput() {
return msgReadThroughput;
}
public float getMsgWrittenThroughput() {
return msgWrittenThroughput;
}
public long getSessionCount() {
return polledSessions.size();
}
private class Worker extends Thread {
boolean stop = false;
private Worker() {
super("StatCollectorWorker-" + id);
}
public void run() {
while (!stop) {
for (Iterator iter = polledSessions.iterator(); iter.hasNext();) {
IoSession session = (IoSession) iter.next();
IoSessionStat sessStat = (IoSessionStat) session
.getAttribute(KEY);
sessStat.lastByteRead = session.getReadBytes();
sessStat.lastByteWrite = session.getWrittenBytes();
sessStat.lastMessageRead = session.getReadMessages();
sessStat.lastMessageWrite = session.getWrittenMessages();
}
// wait polling time
try {
Thread.sleep(pollingInterval);
} catch (InterruptedException e) {
}
float tmpMsgWrittenThroughput = 0f;
float tmpMsgReadThroughput = 0f;
float tmpBytesWrittenThroughput = 0f;
float tmpBytesReadThroughput = 0f;
for (Iterator iter = polledSessions.iterator(); iter.hasNext();) {
// upadating individual session statistics
IoSession session = (IoSession) iter.next();
IoSessionStat sessStat = (IoSessionStat) session
.getAttribute(KEY);
sessStat.byteReadThroughput = (session.getReadBytes() - sessStat.lastByteRead)
/ (pollingInterval / 1000f);
tmpBytesReadThroughput += sessStat.byteReadThroughput;
sessStat.byteWrittenThroughput = (session.getWrittenBytes() - sessStat.lastByteWrite)
/ (pollingInterval / 1000f);
tmpBytesWrittenThroughput += sessStat.byteWrittenThroughput;
sessStat.messageReadThroughput = (session.getReadMessages() - sessStat.lastMessageRead)
/ (pollingInterval / 1000f);
tmpMsgReadThroughput += sessStat.messageReadThroughput;
sessStat.messageWrittenThroughput = (session
.getWrittenMessages() - sessStat.lastMessageWrite)
/ (pollingInterval / 1000f);
tmpMsgWrittenThroughput += sessStat.messageWrittenThroughput;
synchronized (calcLock) {
msgWrittenThroughput = tmpMsgWrittenThroughput;
msgReadThroughput = tmpMsgReadThroughput;
bytesWrittenThroughput = tmpBytesWrittenThroughput;
bytesReadThroughput = tmpBytesReadThroughput;
sessStat.lastPollingTime = System.currentTimeMillis();
}
}
}
}
}
} mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/management/package.html 0000644 0001750 0001750 00000000243 11002320023 026155 0 ustar drazzib drazzib
Utilities that manage and monitor a MINA application.
mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/management/IoSessionStat.java 0000644 0001750 0001750 00000005762 11002320023 027321 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.management;
import org.apache.mina.common.IoSession;
/**
* The collected stats for a session. It's used by {@link StatCollector} to attach
* throughput stats to an {@link IoSession}. You can accces a session stat using
* {@link IoSession} getAttribute method :
*
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
*/
public class IoSessionStat {
long lastByteRead = -1;
long lastByteWrite = -1;
long lastMessageRead = -1;
long lastMessageWrite = -1;
float byteWrittenThroughput = 0;
float byteReadThroughput = 0;
float messageWrittenThroughput = 0;
float messageReadThroughput = 0;
// last time the session was polled
long lastPollingTime = System.currentTimeMillis();
/**
* Bytes read per second
* @return bytes per second
*/
public float getByteReadThroughput() {
return byteReadThroughput;
}
/**
* Bytes written per second
* @return bytes per second
*/
public float getByteWrittenThroughput() {
return byteWrittenThroughput;
}
/**
* Messages read per second
* @return messages per second
*/
public float getMessageReadThroughput() {
return messageReadThroughput;
}
/**
* Messages written per second
* @return messages per second
*/
public float getMessageWrittenThroughput() {
return messageWrittenThroughput;
}
/**
* used for the StatCollector, last polling value
*/
long getLastByteRead() {
return lastByteRead;
}
/**
* used for the StatCollector, last polling value
*/
long getLastByteWrite() {
return lastByteWrite;
}
/**
* used for the StatCollector, last polling value
*/
long getLastMessageRead() {
return lastMessageRead;
}
/**
* used for the StatCollector, last polling value
*/
long getLastMessageWrite() {
return lastMessageWrite;
}
} mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/ 0000755 0001750 0001750 00000000000 11002320023 023615 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/ 0000755 0001750 0001750 00000000000 11044712500 025130 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java 0000644 0001750 0001750 00000004064 11002320023 030472 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.transport.vmpipe;
import java.net.SocketAddress;
/**
* A {@link SocketAddress} which represents in-VM pipe port number.
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 587373 $, $Date: 2007-10-23 11:54:05 +0900 (Tue, 23 Oct 2007) $
*/
public class VmPipeAddress extends SocketAddress implements Comparable {
private static final long serialVersionUID = 3257844376976830515L;
private final int port;
/**
* Creates a new instance with the specifid port number.
*/
public VmPipeAddress(int port) {
this.port = port;
}
/**
* Returns the port number.
*/
public int getPort() {
return port;
}
public int hashCode() {
return port;
}
public boolean equals(Object o) {
if (o == null)
return false;
if (this == o)
return true;
if (o instanceof VmPipeAddress) {
VmPipeAddress that = (VmPipeAddress) o;
return this.port == that.port;
}
return false;
}
public int compareTo(VmPipeAddress o) {
return this.port - o.port;
}
public String toString() {
return "vm:" + port;
}
} mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/package.html 0000644 0001750 0001750 00000001561 11002320023 027401 0 ustar drazzib drazzib
In-VM pipe support which removes the overhead of local loopback communication.
What is 'in-VM pipe'?
In-VM pipe is a direct event forwarding mechanism between two
ProtocolHandlers in the
same Java Virtual Machine. Using in-VM pipe, you can remove the overhead
of encoding and decoding which is caused uselessly by local loopback
network communication. Here are some useful situations possible:
mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java 0000644 0001750 0001750 00000010030 11002320023 030633 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.transport.vmpipe;
import java.io.IOException;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoServiceConfig;
import org.apache.mina.common.IoSessionConfig;
import org.apache.mina.common.support.BaseIoAcceptor;
import org.apache.mina.common.support.BaseIoAcceptorConfig;
import org.apache.mina.common.support.BaseIoSessionConfig;
import org.apache.mina.transport.vmpipe.support.VmPipe;
/**
* Binds the specified {@link IoHandler} to the specified
* {@link VmPipeAddress}.
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 587373 $, $Date: 2007-10-23 11:54:05 +0900 (Tue, 23 Oct 2007) $
*/
public class VmPipeAcceptor extends BaseIoAcceptor {
static final Map boundHandlers = new HashMap();
private static final IoSessionConfig CONFIG = new BaseIoSessionConfig() {
};
private final IoServiceConfig defaultConfig = new BaseIoAcceptorConfig() {
public IoSessionConfig getSessionConfig() {
return CONFIG;
}
};
public void bind(SocketAddress address, IoHandler handler,
IoServiceConfig config) throws IOException {
if (handler == null)
throw new NullPointerException("handler");
if (address != null && !(address instanceof VmPipeAddress))
throw new IllegalArgumentException("address must be VmPipeAddress.");
if (config == null) {
config = getDefaultConfig();
}
synchronized (boundHandlers) {
if (address == null || ((VmPipeAddress) address).getPort() == 0) {
for (int i = 1; i < Integer.MAX_VALUE; i++) {
address = new VmPipeAddress(i);
if (!boundHandlers.containsKey(address)) {
break;
}
}
} else if (boundHandlers.containsKey(address)) {
throw new IOException("Address already bound: " + address);
}
boundHandlers.put(address, new VmPipe(this,
(VmPipeAddress) address, handler, config, getListeners()));
}
getListeners().fireServiceActivated(this, address, handler, config);
}
public void unbind(SocketAddress address) {
if (address == null)
throw new NullPointerException("address");
VmPipe pipe;
synchronized (boundHandlers) {
if (!boundHandlers.containsKey(address)) {
throw new IllegalArgumentException("Address not bound: "
+ address);
}
pipe = boundHandlers.remove(address);
}
getListeners().fireServiceDeactivated(this, pipe.getAddress(),
pipe.getHandler(), pipe.getConfig());
}
public void unbindAll() {
synchronized (boundHandlers) {
for (SocketAddress address : new ArrayList(
boundHandlers.keySet())) {
unbind(address);
}
}
}
public IoServiceConfig getDefaultConfig() {
return defaultConfig;
}
}
mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/support/ 0000755 0001750 0001750 00000000000 11044712500 026644 5 ustar drazzib drazzib mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipe.java 0000644 0001750 0001750 00000004361 11002320023 030700 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.transport.vmpipe.support;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoServiceConfig;
import org.apache.mina.common.support.IoServiceListenerSupport;
import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
import org.apache.mina.transport.vmpipe.VmPipeAddress;
/**
* @todo Document me!
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 585081 $, $Date: 2007-10-16 17:45:14 +0900 (Tue, 16 Oct 2007) $
*/
public class VmPipe {
private final VmPipeAcceptor acceptor;
private final VmPipeAddress address;
private final IoHandler handler;
private final IoServiceConfig config;
private final IoServiceListenerSupport listeners;
public VmPipe(VmPipeAcceptor acceptor, VmPipeAddress address,
IoHandler handler, IoServiceConfig config,
IoServiceListenerSupport listeners) {
this.acceptor = acceptor;
this.address = address;
this.handler = handler;
this.config = config;
this.listeners = listeners;
}
public VmPipeAcceptor getAcceptor() {
return acceptor;
}
public VmPipeAddress getAddress() {
return address;
}
public IoHandler getHandler() {
return handler;
}
public IoServiceConfig getConfig() {
return config;
}
public IoServiceListenerSupport getListeners() {
return listeners;
}
} mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/support/package.html 0000644 0001750 0001750 00000000271 11002320023 031112 0 ustar drazzib drazzib
Internal classes used by org.apache.mina.transport.vmpipe package.
././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011562 L ustar root root mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.java mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.0000644 0001750 0001750 00000007652 11002320023 033333 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.transport.vmpipe.support;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.mina.common.IdleStatus;
/**
* Dectects idle sessions and fires sessionIdle events to them.
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 585077 $, $Date: 2007-10-16 17:36:14 +0900 (Tue, 16 Oct 2007) $
*/
public class VmPipeIdleStatusChecker {
private static final VmPipeIdleStatusChecker INSTANCE = new VmPipeIdleStatusChecker();
public static VmPipeIdleStatusChecker getInstance() {
return INSTANCE;
}
private final Set sessions = new HashSet();
private final Worker worker = new Worker();
private VmPipeIdleStatusChecker() {
worker.start();
}
public void addSession(VmPipeSessionImpl session) {
synchronized (sessions) {
sessions.add(session);
}
}
private class Worker extends Thread {
private Worker() {
super("VmPipeIdleStatusChecker");
setDaemon(true);
}
public void run() {
for (;;) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
long currentTime = System.currentTimeMillis();
synchronized (sessions) {
Iterator it = sessions.iterator();
while (it.hasNext()) {
VmPipeSessionImpl session = it.next();
if (!session.isConnected()) {
it.remove();
} else {
notifyIdleSession(session, currentTime);
}
}
}
}
}
}
private void notifyIdleSession(VmPipeSessionImpl session, long currentTime) {
notifyIdleSession0(session, currentTime, session
.getIdleTimeInMillis(IdleStatus.BOTH_IDLE),
IdleStatus.BOTH_IDLE, Math.max(session.getLastIoTime(), session
.getLastIdleTime(IdleStatus.BOTH_IDLE)));
notifyIdleSession0(session, currentTime, session
.getIdleTimeInMillis(IdleStatus.READER_IDLE),
IdleStatus.READER_IDLE, Math.max(session.getLastReadTime(),
session.getLastIdleTime(IdleStatus.READER_IDLE)));
notifyIdleSession0(session, currentTime, session
.getIdleTimeInMillis(IdleStatus.WRITER_IDLE),
IdleStatus.WRITER_IDLE, Math.max(session.getLastWriteTime(),
session.getLastIdleTime(IdleStatus.WRITER_IDLE)));
}
private void notifyIdleSession0(VmPipeSessionImpl session,
long currentTime, long idleTime, IdleStatus status, long lastIoTime) {
if (idleTime > 0 && lastIoTime != 0
&& (currentTime - lastIoTime) >= idleTime) {
session.increaseIdleCount(status);
session.getFilterChain().fireSessionIdle(session, status);
}
}
} mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java 0000644 0001750 0001750 00000021514 11002320023 033010 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.transport.vmpipe.support;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.IoFilter.WriteRequest;
import org.apache.mina.common.support.AbstractIoFilterChain;
/**
* @todo Document me!
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 635494 $, $Date: 2008-03-10 18:04:45 +0900 (Mon, 10 Mar 2008) $
*/
public class VmPipeFilterChain extends AbstractIoFilterChain {
private final Queue eventQueue = new ConcurrentLinkedQueue();
private volatile boolean flushEnabled;
private volatile boolean sessionOpened;
public VmPipeFilterChain(IoSession session) {
super(session);
}
public void start() {
flushEnabled = true;
flushEvents();
flushPendingDataQueues( (VmPipeSessionImpl) getSession() );
}
private void pushEvent(Event e) {
eventQueue.offer(e);
if ( flushEnabled ) {
flushEvents();
}
}
private void flushEvents() {
Event e;
while ((e = eventQueue.poll()) != null) {
fireEvent(e);
}
}
private void fireEvent(Event e) {
VmPipeSessionImpl session = (VmPipeSessionImpl) getSession();
EventType type = e.getType();
Object data = e.getData();
if (type == EventType.RECEIVED) {
if( sessionOpened && session.getTrafficMask().isReadable() && session.getLock().tryLock()) {
try {
int byteCount = 1;
if (data instanceof ByteBuffer) {
byteCount = ((ByteBuffer) data).remaining();
}
session.increaseReadBytes(byteCount);
super.fireMessageReceived(session, data);
} finally {
session.getLock().unlock();
}
flushPendingDataQueues( session );
} else {
session.pendingDataQueue.add(data);
}
} else if (type == EventType.WRITE) {
super.fireFilterWrite(session, (WriteRequest) data);
} else if (type == EventType.SENT) {
super.fireMessageSent(session, (WriteRequest) data);
} else if (type == EventType.EXCEPTION) {
super.fireExceptionCaught(session, (Throwable) data);
} else if (type == EventType.IDLE) {
super.fireSessionIdle(session, (IdleStatus) data);
} else if (type == EventType.OPENED) {
super.fireSessionOpened(session);
sessionOpened = true;
} else if (type == EventType.CREATED) {
session.getLock().lock();
try {
super.fireSessionCreated(session);
} finally {
session.getLock().unlock();
}
} else if (type == EventType.CLOSED) {
super.fireSessionClosed(session);
} else if (type == EventType.CLOSE) {
super.fireFilterClose(session);
}
}
private static void flushPendingDataQueues( VmPipeSessionImpl s ) {
s.updateTrafficMask();
s.getRemoteSession().updateTrafficMask();
}
@Override
public void fireFilterClose(IoSession session) {
pushEvent(new Event(EventType.CLOSE, null));
}
@Override
public void fireFilterWrite(IoSession session, WriteRequest writeRequest) {
pushEvent(new Event(EventType.WRITE, writeRequest));
}
@Override
public void fireExceptionCaught(IoSession session, Throwable cause) {
pushEvent(new Event(EventType.EXCEPTION, cause));
}
@Override
public void fireMessageSent(IoSession session, WriteRequest request) {
pushEvent(new Event(EventType.SENT, request));
}
@Override
public void fireSessionClosed(IoSession session) {
pushEvent(new Event(EventType.CLOSED, null));
}
@Override
public void fireSessionCreated(IoSession session) {
pushEvent(new Event(EventType.CREATED, null));
}
@Override
public void fireSessionIdle(IoSession session, IdleStatus status) {
pushEvent(new Event(EventType.IDLE, status));
}
@Override
public void fireSessionOpened(IoSession session) {
pushEvent(new Event(EventType.OPENED, null));
}
@Override
public void fireMessageReceived(IoSession session, Object message) {
pushEvent(new Event(EventType.RECEIVED, message));
}
@Override
protected void doWrite(IoSession session, WriteRequest writeRequest) {
VmPipeSessionImpl s = (VmPipeSessionImpl) session;
if (s.isConnected()) {
if ( s.getTrafficMask().isWritable() && s.getLock().tryLock()) {
try {
Object message = writeRequest.getMessage();
int byteCount = 1;
Object messageCopy = message;
if (message instanceof ByteBuffer) {
ByteBuffer rb = (ByteBuffer) message;
rb.mark();
byteCount = rb.remaining();
ByteBuffer wb = ByteBuffer.allocate(rb.remaining());
wb.put(rb);
wb.flip();
rb.reset();
messageCopy = wb;
}
// Avoid unwanted side effect that scheduledWrite* becomes negative
// by increasing them.
s.increaseScheduledWriteBytes(byteCount);
s.increaseScheduledWriteRequests();
s.increaseWrittenBytes(byteCount);
s.increaseWrittenMessages();
s.getRemoteSession().getFilterChain().fireMessageReceived(
s.getRemoteSession(), messageCopy);
s.getFilterChain().fireMessageSent(s, writeRequest);
} finally {
s.getLock().unlock();
}
flushPendingDataQueues( s );
} else {
s.pendingDataQueue.add(writeRequest);
}
} else {
writeRequest.getFuture().setWritten(false);
}
}
@Override
protected void doClose(IoSession session) {
VmPipeSessionImpl s = (VmPipeSessionImpl) session;
try {
s.getLock().lock();
if (!session.getCloseFuture().isClosed()) {
s.getServiceListeners().fireSessionDestroyed(s);
s.getRemoteSession().close();
}
} finally {
s.getLock().unlock();
}
}
// FIXME Copied and pasted from {@link ExecutorFilter}.
private static class EventType {
public static final EventType CREATED = new EventType("CREATED");
public static final EventType OPENED = new EventType("OPENED");
public static final EventType CLOSED = new EventType("CLOSED");
public static final EventType RECEIVED = new EventType("RECEIVED");
public static final EventType SENT = new EventType("SENT");
public static final EventType IDLE = new EventType("IDLE");
public static final EventType EXCEPTION = new EventType("EXCEPTION");
public static final EventType WRITE = new EventType("WRITE");
public static final EventType CLOSE = new EventType("CLOSE");
private final String value;
private EventType(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
private static class Event {
private final EventType type;
private final Object data;
private Event(EventType type, Object data) {
this.type = type;
this.data = data;
}
public Object getData() {
return data;
}
public EventType getType() {
return type;
}
}
}
mina-1.1.7.dfsg/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java 0000644 0001750 0001750 00000014055 11002320023 033067 0 ustar drazzib drazzib /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.transport.vmpipe.support;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.mina.common.IoFilter.WriteRequest;
import org.apache.mina.common.IoFilterChain;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoService;
import org.apache.mina.common.IoServiceConfig;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.IoSessionConfig;
import org.apache.mina.common.TransportType;
import org.apache.mina.common.support.BaseIoSession;
import org.apache.mina.common.support.BaseIoSessionConfig;
import org.apache.mina.common.support.IoServiceListenerSupport;
/**
* A {@link IoSession} for in-VM transport (VM_PIPE).
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 575603 $, $Date: 2007-09-14 19:04:45 +0900 (Fri, 14 Sep 2007) $
*/
public class VmPipeSessionImpl extends BaseIoSession {
private static final IoSessionConfig CONFIG = new BaseIoSessionConfig() {
};
private final IoService service;
private final IoServiceConfig serviceConfig;
private final IoServiceListenerSupport serviceListeners;
private final SocketAddress localAddress;
private final SocketAddress remoteAddress;
private final SocketAddress serviceAddress;
private final IoHandler handler;
private final VmPipeFilterChain filterChain;
private final VmPipeSessionImpl remoteSession;
private final Lock lock;
final BlockingQueue