You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2006/03/27 09:34:16 UTC
svn commit: r389039 - in
/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec:
SynchronizedProtocolDecoder.java SynchronizedProtocolEncoder.java
Author: trustin
Date: Sun Mar 26 23:34:16 2006
New Revision: 389039
URL: http://svn.apache.org/viewcvs?rev=389039&view=rev
Log:
Added SynchronizedProtocolEncoder and SynchronizedProtocolDecoder
Added:
directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java (with props)
directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java (with props)
Added: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java?rev=389039&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java Sun Mar 26 23:34:16 2006
@@ -0,0 +1,72 @@
+/*
+ * @(#) $Id$
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A {@link ProtocolDecoder} implementation which decorates an existing decoder
+ * to be thread-safe. Please be careful if you're going to use this decorator
+ * because it can be a root of performance degradation in a multi-thread
+ * environment.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SynchronizedProtocolDecoder implements ProtocolDecoder
+{
+ private final ProtocolDecoder decoder;
+
+ /**
+ * Creates a new instance which decorates the specified <tt>decoder</tt>.
+ */
+ public SynchronizedProtocolDecoder( ProtocolDecoder decoder )
+ {
+ if( decoder == null )
+ {
+ throw new NullPointerException( "decoder" );
+ }
+ this.decoder = decoder;
+ }
+
+ /**
+ * Returns the decoder this decoder is decorating.
+ */
+ public ProtocolDecoder getDecoder()
+ {
+ return decoder;
+ }
+
+ public void decode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out ) throws Exception
+ {
+ synchronized( decoder )
+ {
+ decoder.decode( session, in, out );
+ }
+ }
+
+ public void dispose( IoSession session ) throws Exception
+ {
+ synchronized( decoder )
+ {
+ decoder.dispose( session );
+ }
+ }
+}
Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java?rev=389039&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java (added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java Sun Mar 26 23:34:16 2006
@@ -0,0 +1,71 @@
+/*
+ * @(#) $Id$
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.codec;
+
+import org.apache.mina.common.IoSession;
+
+/**
+ * A {@link ProtocolEncoder} implementation which decorates an existing encoder
+ * to be thread-safe. Please be careful if you're going to use this decorator
+ * because it can be a root of performance degradation in a multi-thread
+ * environment.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SynchronizedProtocolEncoder implements ProtocolEncoder
+{
+ private final ProtocolEncoder encoder;
+
+ /**
+ * Creates a new instance which decorates the specified <tt>encoder</tt>.
+ */
+ public SynchronizedProtocolEncoder( ProtocolEncoder encoder )
+ {
+ if( encoder == null )
+ {
+ throw new NullPointerException( "encoder" );
+ }
+ this.encoder = encoder;
+ }
+
+ /**
+ * Returns the encoder this encoder is decorating.
+ */
+ public ProtocolEncoder getEncoder()
+ {
+ return encoder;
+ }
+
+ public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws Exception
+ {
+ synchronized( encoder )
+ {
+ encoder.encode( session, message, out );
+ }
+ }
+
+ public void dispose( IoSession session ) throws Exception
+ {
+ synchronized( encoder )
+ {
+ encoder.dispose( session );
+ }
+ }
+}
Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision