Swap Server from Builder to HandlerRegistry.
The idea is that Server would be provided a HandlerRegistry at construction time.
This has a simplistic implementation of HandlerRegistry. If we like the API, then I can implement a lock-less version as we find need.
Most classes are still under Server so that it is obvious what changes were made. Moving things out of Server would be a separate CL.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=73334671
diff --git a/core/src/main/java/com/google/net/stubby/HandlerRegistry.java b/core/src/main/java/com/google/net/stubby/HandlerRegistry.java
new file mode 100644
index 0000000..33ad884
--- /dev/null
+++ b/core/src/main/java/com/google/net/stubby/HandlerRegistry.java
@@ -0,0 +1,34 @@
+package com.google.net.stubby;
+
+import com.google.net.stubby.Server.MethodDefinition;
+import com.google.net.stubby.Server.ServiceDefinition;
+
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.ThreadSafe;
+
+/** Registry of services and their methods for dispatching incoming calls. */
+@ThreadSafe
+public abstract class HandlerRegistry {
+ /** Lookup full method name, starting with '/'. Returns {@code null} if method not found. */
+ @Nullable
+ public abstract Method lookupMethod(String methodName);
+
+ /** A method definition and its parent's service definition. */
+ public static final class Method {
+ private final ServiceDefinition serviceDef;
+ private final MethodDefinition methodDef;
+
+ public Method(ServiceDefinition serviceDef, MethodDefinition methodDef) {
+ this.serviceDef = serviceDef;
+ this.methodDef = methodDef;
+ }
+
+ public ServiceDefinition getServiceDefinition() {
+ return serviceDef;
+ }
+
+ public MethodDefinition getMethodDefinition() {
+ return methodDef;
+ }
+ }
+}