From 3ee999ddb1ed8db94eebb2a2531b6bf318e2e361 Mon Sep 17 00:00:00 2001 From: Min Zhou Date: Thu, 16 Jul 2015 11:24:46 -0700 Subject: [PATCH] Reformat some classes --- .../lightning/rpc/NamedThreadFactory.java | 64 +++++++++---------- .../server/SimpleProcessorServerHandler.java | 53 ++++++++------- 2 files changed, 58 insertions(+), 59 deletions(-) diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/NamedThreadFactory.java b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/NamedThreadFactory.java index 29a9516..ed7151c 100644 --- a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/NamedThreadFactory.java +++ b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/NamedThreadFactory.java @@ -5,41 +5,41 @@ /** * Help for threadpool to set thread name - * */ public class NamedThreadFactory implements ThreadFactory { - - static final AtomicInteger poolNumber = new AtomicInteger(1); - - final AtomicInteger threadNumber = new AtomicInteger(1); - final ThreadGroup group; - final String namePrefix; - final boolean isDaemon; - - public NamedThreadFactory() { - this("pool"); - } - public NamedThreadFactory(String name) { - this(name, false); - } - public NamedThreadFactory(String preffix, boolean daemon) { - SecurityManager s = System.getSecurityManager(); - group = (s != null) ? s.getThreadGroup() : Thread.currentThread() - .getThreadGroup(); - namePrefix = preffix + "-" + poolNumber.getAndIncrement() + "-thread-"; - isDaemon = daemon; - } - - - public Thread newThread(Runnable r) { - Thread t = new Thread(group, r, namePrefix - + threadNumber.getAndIncrement(), 0); - t.setDaemon(isDaemon); - if (t.getPriority() != Thread.NORM_PRIORITY) { - t.setPriority(Thread.NORM_PRIORITY); - } - return t; + static final AtomicInteger poolNumber = new AtomicInteger(1); + + final AtomicInteger threadNumber = new AtomicInteger(1); + final ThreadGroup group; + final String namePrefix; + final boolean isDaemon; + + public NamedThreadFactory() { + this("pool"); + } + + public NamedThreadFactory(String name) { + this(name, false); + } + + public NamedThreadFactory(String preffix, boolean daemon) { + SecurityManager s = System.getSecurityManager(); + group = (s != null) ? s.getThreadGroup() : Thread.currentThread() + .getThreadGroup(); + namePrefix = preffix + "-" + poolNumber.getAndIncrement() + "-thread-"; + isDaemon = daemon; + } + + + public Thread newThread(Runnable r) { + Thread t = new Thread(group, r, namePrefix + + threadNumber.getAndIncrement(), 0); + t.setDaemon(isDaemon); + if (t.getPriority() != Thread.NORM_PRIORITY) { + t.setPriority(Thread.NORM_PRIORITY); } + return t; + } } diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/server/SimpleProcessorServerHandler.java b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/server/SimpleProcessorServerHandler.java index 68d1794..86cb27c 100644 --- a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/server/SimpleProcessorServerHandler.java +++ b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/server/SimpleProcessorServerHandler.java @@ -9,34 +9,33 @@ import info.minzhou.lightning.rpc.RequestWrapper; import info.minzhou.lightning.rpc.ResponseWrapper; + /** * Direct Call RPC Server Handler - * */ -public class SimpleProcessorServerHandler implements ServerHandler{ - - private static final Log LOGGER = LogFactory.getLog(SimpleProcessorServerHandler.class); - - private Map processors = new ConcurrentHashMap(); - - public void registerProcessor(String instanceName,Object instance){ - processors.put(instanceName, (ServerProcessor)instance); - } - - public ResponseWrapper handleRequest(final RequestWrapper request){ - ResponseWrapper responseWrapper = new ResponseWrapper(request.getId(),request.getCodecType(),request.getProtocolType()); - try{ - String argType = null; - if(request.getArgTypes() != null && request.getArgTypes()[0] != null){ - argType = new String(request.getArgTypes()[0]); - } - Object requestObject = Codecs.getDecoder(request.getCodecType()).decode(argType,(byte[])request.getMessage()); - responseWrapper.setResponse(processors.get(requestObject.getClass().getName()).handle(requestObject)); - } - catch(Exception e){ - LOGGER.error("server direct call handler to handle request error",e); - responseWrapper.setException(e); - } - return responseWrapper; - } +public class SimpleProcessorServerHandler implements ServerHandler { + + private static final Log LOGGER = LogFactory.getLog(SimpleProcessorServerHandler.class); + + private Map processors = new ConcurrentHashMap(); + + public void registerProcessor(String instanceName, Object instance) { + processors.put(instanceName, (ServerProcessor) instance); + } + + public ResponseWrapper handleRequest(final RequestWrapper request) { + ResponseWrapper responseWrapper = new ResponseWrapper(request.getId(), request.getCodecType(), request.getProtocolType()); + try { + String argType = null; + if (request.getArgTypes() != null && request.getArgTypes()[0] != null) { + argType = new String(request.getArgTypes()[0]); + } + Object requestObject = Codecs.getDecoder(request.getCodecType()).decode(argType, (byte[]) request.getMessage()); + responseWrapper.setResponse(processors.get(requestObject.getClass().getName()).handle(requestObject)); + } catch (Exception e) { + LOGGER.error("server direct call handler to handle request error", e); + responseWrapper.setException(e); + } + return responseWrapper; + } }