forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
收到一个 Request/Response 时,把消息体保存起来不立即做反序列化,派发到业务线程后再把消息体进行反序列化
- Loading branch information
kimi
committed
Jul 1, 2012
1 parent
20c1f7f
commit fbf1387
Showing
10 changed files
with
611 additions
and
170 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 1999-2011 Alibaba Group. | ||
* | ||
* 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 com.alibaba.dubbo.common.utils; | ||
|
||
/** | ||
* @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a> | ||
*/ | ||
public abstract class Assert { | ||
|
||
protected Assert() {} | ||
|
||
public static void notNull(Object obj, String message) { | ||
if (obj == null) { | ||
throw new IllegalArgumentException(message); | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/Decodeable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 1999-2011 Alibaba Group. | ||
* | ||
* 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 com.alibaba.dubbo.remoting; | ||
|
||
/** | ||
* @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a> | ||
*/ | ||
public interface Decodeable { | ||
|
||
public void decode() throws Exception; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...g/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/CodecSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 1999-2011 Alibaba Group. | ||
* | ||
* 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 com.alibaba.dubbo.remoting.transport; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import com.alibaba.dubbo.common.Constants; | ||
import com.alibaba.dubbo.common.URL; | ||
import com.alibaba.dubbo.common.extension.ExtensionLoader; | ||
import com.alibaba.dubbo.common.logger.Logger; | ||
import com.alibaba.dubbo.common.logger.LoggerFactory; | ||
import com.alibaba.dubbo.common.serialize.Serialization; | ||
|
||
/** | ||
* @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a> | ||
*/ | ||
public class CodecSupport { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(CodecSupport.class); | ||
|
||
private CodecSupport() { | ||
} | ||
|
||
private static Map<Byte, Serialization> ID_SERIALIZATION_MAP = new HashMap<Byte, Serialization>(); | ||
|
||
static { | ||
Set<String> supportedExtensions = ExtensionLoader.getExtensionLoader(Serialization.class).getSupportedExtensions(); | ||
for (String name : supportedExtensions) { | ||
Serialization serialization = ExtensionLoader.getExtensionLoader(Serialization.class).getExtension(name); | ||
byte idByte = serialization.getContentTypeId(); | ||
if (ID_SERIALIZATION_MAP.containsKey(idByte)) { | ||
logger.error("Serialization extension " + serialization.getClass().getName() | ||
+ " has duplicate id to Serialization extension " | ||
+ ID_SERIALIZATION_MAP.get(idByte).getClass().getName() | ||
+ ", ignore this Serialization extension"); | ||
continue; | ||
} | ||
ID_SERIALIZATION_MAP.put(idByte, serialization); | ||
} | ||
} | ||
|
||
public static Serialization getSerializationById(Byte id) { | ||
return ID_SERIALIZATION_MAP.get(id); | ||
} | ||
|
||
public static Serialization getSerialization(URL url) { | ||
return ExtensionLoader.getExtensionLoader(Serialization.class).getExtension( | ||
url.getParameter(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION)); | ||
} | ||
|
||
public static Serialization getSerialization(URL url, Byte id) { | ||
Serialization result = getSerializationById(id); | ||
if (result == null) { | ||
result = getSerialization(url); | ||
} | ||
return result; | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
.../dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/DecodeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 1999-2011 Alibaba Group. | ||
* | ||
* 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 com.alibaba.dubbo.remoting.transport; | ||
|
||
import com.alibaba.dubbo.common.logger.Logger; | ||
import com.alibaba.dubbo.common.logger.LoggerFactory; | ||
import com.alibaba.dubbo.common.utils.Assert; | ||
import com.alibaba.dubbo.remoting.Channel; | ||
import com.alibaba.dubbo.remoting.ChannelHandler; | ||
import com.alibaba.dubbo.remoting.Decodeable; | ||
import com.alibaba.dubbo.remoting.RemotingException; | ||
import com.alibaba.dubbo.remoting.exchange.Request; | ||
import com.alibaba.dubbo.remoting.exchange.Response; | ||
|
||
/** | ||
* @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a> | ||
*/ | ||
public class DecodeHandler implements ChannelHandlerDelegate { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(DecodeHandler.class); | ||
|
||
private ChannelHandler handler; | ||
|
||
public DecodeHandler(ChannelHandler handler) { | ||
Assert.notNull(handler, "handler == null"); | ||
this.handler = handler; | ||
} | ||
|
||
public ChannelHandler getHandler() { | ||
if (handler instanceof ChannelHandlerDelegate) { | ||
return ((ChannelHandlerDelegate)handler).getHandler(); | ||
} | ||
return handler; | ||
} | ||
|
||
public void connected(Channel channel) throws RemotingException { | ||
handler.connected(channel); | ||
} | ||
|
||
public void disconnected(Channel channel) throws RemotingException { | ||
handler.disconnected(channel); | ||
} | ||
|
||
public void sent(Channel channel, Object message) throws RemotingException { | ||
handler.sent(channel, message); | ||
} | ||
|
||
public void received(Channel channel, Object message) throws RemotingException { | ||
if (message instanceof Decodeable) { | ||
decode(message); | ||
} | ||
|
||
if (message instanceof Request) { | ||
decode(((Request)message).getData()); | ||
} | ||
|
||
if (message instanceof Response) { | ||
decode( ((Response)message).getResult()); | ||
} | ||
|
||
handler.received(channel, message); | ||
} | ||
|
||
public void caught(Channel channel, Throwable exception) throws RemotingException { | ||
handler.caught(channel, exception); | ||
} | ||
|
||
private void decode(Object message) { | ||
if (message != null && message instanceof Decodeable) { | ||
try { | ||
((Decodeable)message).decode(); | ||
if (log.isDebugEnabled()) { | ||
log.debug(new StringBuilder(32).append("Decode decodeable message ") | ||
.append(message.getClass().getName()).toString()); | ||
} | ||
} catch (Throwable e) { | ||
if (log.isWarnEnabled()) { | ||
log.warn( | ||
new StringBuilder(32) | ||
.append("Call Decodeable.decode failed: ") | ||
.append(e.getMessage()).toString(), | ||
e); | ||
} | ||
} // ~ end of catch | ||
} // ~ end of if | ||
} // ~ end of method decode | ||
|
||
} |
Oops, something went wrong.