-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed a lot of nits and reorg'ed the code
- Loading branch information
Showing
15 changed files
with
218 additions
and
134 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/connector/src/main/java/com/google/grpcweb/GrpcServiceConnectionManager.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,22 @@ | ||
package com.google.grpcweb; | ||
|
||
import io.grpc.ManagedChannel; | ||
import io.grpc.ManagedChannelBuilder; | ||
|
||
/** | ||
* Manages the connection pool to talk to the grpc-service | ||
*/ | ||
class GrpcServiceConnectionManager { | ||
private final int mGrpcPortNum; | ||
|
||
GrpcServiceConnectionManager(int grpcPortNum) { | ||
mGrpcPortNum = grpcPortNum; | ||
} | ||
|
||
ManagedChannel getChannel() { | ||
// TODO: Manage a connection pool. | ||
return ManagedChannelBuilder.forAddress("localhost", mGrpcPortNum) | ||
.usePlaintext() | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/connector/src/main/java/com/google/grpcweb/GrpcWebTrafficHandler.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,24 @@ | ||
package com.google.grpcweb; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
/** | ||
* The main class that handles all the grpc-web traffic. | ||
*/ | ||
public class GrpcWebTrafficHandler { | ||
private final RequestHandler mRequestHandler; | ||
private final Factory mFactory; | ||
|
||
public GrpcWebTrafficHandler(int grpcPortNum) { | ||
mFactory = new Factory(grpcPortNum); | ||
mRequestHandler = new RequestHandler(mFactory); | ||
} | ||
|
||
@VisibleForTesting | ||
GrpcWebTrafficHandler(Factory factory) { | ||
mFactory = factory; | ||
mRequestHandler = new RequestHandler(factory); | ||
} | ||
|
||
public RequestHandler getRequestHandler() { return mRequestHandler;} | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
src/connector/src/main/java/com/google/grpcweb/example/GrpcWebListener.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 @@ | ||
package com.google.grpcweb.example; | ||
|
||
import com.google.grpcweb.GrpcWebTrafficHandler; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* A simple class w/ single method to start listening on the given grpc-web port#. | ||
*/ | ||
class GrpcWebListener { | ||
private static final Logger LOGGER = Logger.getLogger(GrpcWebListener.class.getName()); | ||
private final int mGrpcPort; | ||
private final int mGrpcWebPort; | ||
|
||
GrpcWebListener(int grpcPort, int grpcWebPort) { | ||
mGrpcPort = grpcPort; | ||
mGrpcWebPort = grpcWebPort; | ||
} | ||
|
||
void listenForGrpcWebReq() throws Exception { | ||
// Initialize the Main Module for grpc-web | ||
// It takes a single param: the port# the gRPC Service itself is listening on. | ||
// It is used by the grpc-web code to talk to the service by connecting to it on that port. | ||
GrpcWebTrafficHandler grpcWebTrafficHandler = new GrpcWebTrafficHandler(mGrpcPort); | ||
|
||
// Start a jetty server to listen on the grpc-web port# | ||
org.eclipse.jetty.server.Server jServer = new org.eclipse.jetty.server.Server(mGrpcWebPort); | ||
jServer.setHandler(grpcWebTrafficHandler.getRequestHandler()); | ||
jServer.start(); | ||
|
||
LOGGER.info("**** started gRPC-web Service on port# " + mGrpcWebPort); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/connector/src/main/java/com/google/grpcweb/example/TestEchoService.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,28 @@ | ||
package com.google.grpcweb.example; | ||
|
||
import io.grpc.Server; | ||
import io.grpc.ServerBuilder; | ||
import java.util.logging.Logger; | ||
|
||
public class TestEchoService { | ||
private static final Logger LOGGER = Logger.getLogger(TestEchoService.class.getName()); | ||
|
||
private static Server startGrpcService(int port) throws Exception { | ||
Server grpcServer = ServerBuilder.forPort(port) | ||
.addService(new EchoService()) | ||
.build(); | ||
grpcServer.start(); | ||
LOGGER.info("**** started gRPC Service on port# " + port); | ||
return grpcServer; | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
// PUNT accept these as flags in pom.xml | ||
int grpcPort = 9090; | ||
int grpcWebPort = 8081; | ||
|
||
Server grpcServer = startGrpcService(grpcPort); | ||
new GrpcWebListener(grpcPort, grpcWebPort).listenForGrpcWebReq(); | ||
grpcServer.awaitTermination(); | ||
} | ||
} |
File renamed without changes.