From 059290ce3a008f281e7e64fd263cfb09d92da19e Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Sat, 17 Dec 2011 00:14:36 +0000 Subject: [PATCH] HADOOP-7931. o.a.h.ipc.WritableRpcEngine should have a way to force initialization. Contributed by Aaron T. Myers git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1215358 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 ++ .../apache/hadoop/ipc/WritableRpcEngine.java | 35 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 21eda1b32f..aba8ce050c 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -141,6 +141,9 @@ Trunk (unreleased changes) HADOOP-7892. IPC logs too verbose after "RpcKind" introduction (todd) + HADOOP-7931. o.a.h.ipc.WritableRpcEngine should have a way to force + initialization (atm) + OPTIMIZATIONS HADOOP-7761. Improve the performance of raw comparisons. (todd) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/WritableRpcEngine.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/WritableRpcEngine.java index 25f46f13e2..19a496809b 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/WritableRpcEngine.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/WritableRpcEngine.java @@ -48,17 +48,38 @@ public class WritableRpcEngine implements RpcEngine { private static final Log LOG = LogFactory.getLog(RPC.class); - static { // Register the rpcRequest deserializer for WritableRpcEngine - org.apache.hadoop.ipc.Server.registerProtocolEngine(RpcKind.RPC_WRITABLE, - Invocation.class, new Server.WritableRpcInvoker()); - } - - //writableRpcVersion should be updated if there is a change //in format of the rpc messages. // 2L - added declared class to Invocation - public static final long writableRpcVersion = 2L; + public static final long writableRpcVersion = 2L; + + /** + * Whether or not this class has been initialized. + */ + private static boolean isInitialized = false; + + static { + ensureInitialized(); + } + + /** + * Initialize this class if it isn't already. + */ + public static synchronized void ensureInitialized() { + if (!isInitialized) { + initialize(); + } + } + + /** + * Register the rpcRequest deserializer for WritableRpcEngine + */ + private static synchronized void initialize() { + org.apache.hadoop.ipc.Server.registerProtocolEngine(RpcKind.RPC_WRITABLE, + Invocation.class, new Server.WritableRpcInvoker()); + isInitialized = true; + } /** A method invocation, including the method name and its parameters.*/