Skip to content
Permalink
Browse files

refactor(grpc): moving zmqclient to client module

  • Loading branch information...
hanxiao committed Aug 9, 2019
1 parent 5e3409e commit 8516096d053e0a216440f2f78cafdab088eaeb43
@@ -0,0 +1,53 @@
# Tencent is pleased to support the open source community by making GNES available.
#
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
# 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.


import zmq

from ..helper import set_logger
from ..proto import send_message, gnes_pb2, recv_message
from ..service.base import build_socket


class ZmqClient:

def __init__(self, args):
self.args = args
self.identity = args.identity if 'identity' in args else None
self.logger = set_logger(self.__class__.__name__, self.args.verbose)
self.ctx = zmq.Context()
self.ctx.setsockopt(zmq.LINGER, 0)
self.receiver, recv_addr = build_socket(self.ctx, self.args.host_in, self.args.port_in, self.args.socket_in,
getattr(self, 'identity', None))
self.sender, send_addr = build_socket(self.ctx, self.args.host_out, self.args.port_out, self.args.socket_out,
getattr(self, 'identity', None))
self.logger.info('send via %s, receive via %s' % (send_addr, recv_addr))

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.close()

def close(self):
self.sender.close()
self.receiver.close()
self.ctx.term()

def send_message(self, message: "gnes_pb2.Message", timeout: int = -1):
send_message(self.sender, message, timeout=timeout)

def recv_message(self, timeout: int = -1) -> gnes_pb2.Message:
return recv_message(self.receiver, timeout=timeout)
@@ -14,8 +14,6 @@
# limitations under the License.




# A key-value map for Class to the (module)file it located in
from ..base import register_all_class

@@ -14,8 +14,6 @@
# limitations under the License.




from typing import List, Any

import numpy as np
@@ -14,7 +14,6 @@
# limitations under the License.



# A key-value map for Class to the (module)file it located in
from ..base import register_all_class

@@ -14,7 +14,6 @@
# limitations under the License.



from typing import List, Any, Union, Callable, Tuple

import numpy as np
@@ -19,45 +19,10 @@
from concurrent import futures

import grpc
import zmq

from .base import build_socket
from ..client.base import ZmqClient
from ..helper import set_logger
from ..proto import gnes_pb2, gnes_pb2_grpc, send_message, recv_message

__all__ = ['GRPCFrontend']


class ZmqClient:

def __init__(self, args):
self.args = args
self.identity = args.identity if 'identity' in args else None
self.logger = set_logger(self.__class__.__name__, self.args.verbose)
self.ctx = zmq.Context()
self.ctx.setsockopt(zmq.LINGER, 0)
self.receiver, recv_addr = build_socket(self.ctx, self.args.host_in, self.args.port_in, self.args.socket_in,
getattr(self, 'identity', None))
self.sender, send_addr = build_socket(self.ctx, self.args.host_out, self.args.port_out, self.args.socket_out,
getattr(self, 'identity', None))
self.logger.info('send via %s, receive via %s' % (send_addr, recv_addr))

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.close()

def close(self):
self.sender.close()
self.receiver.close()
self.ctx.term()

def send_message(self, message: "gnes_pb2.Message", timeout: int = -1):
send_message(self.sender, message, timeout=timeout)

def recv_message(self, timeout: int = -1) -> gnes_pb2.Message:
return recv_message(self.receiver, timeout=timeout)
from ..proto import gnes_pb2, gnes_pb2_grpc


class GRPCFrontend:
@@ -2,8 +2,8 @@
import unittest

from gnes.cli.parser import set_preprocessor_service_parser, _set_client_parser
from gnes.client.base import ZmqClient
from gnes.proto import gnes_pb2, RequestGenerator, blob2array
from gnes.service.grpc import ZmqClient
from gnes.service.preprocessor import PreprocessorService


@@ -3,8 +3,8 @@
import zipfile

from gnes.cli.parser import set_preprocessor_service_parser, _set_client_parser
from gnes.client.base import ZmqClient
from gnes.proto import gnes_pb2, RequestGenerator, blob2array
from gnes.service.grpc import ZmqClient
from gnes.service.preprocessor import PreprocessorService


@@ -2,9 +2,8 @@
import unittest

from gnes.cli.parser import set_preprocessor_service_parser, _set_client_parser
from gnes.composer.base import YamlComposer
from gnes.client.base import ZmqClient
from gnes.proto import gnes_pb2
from gnes.service.grpc import ZmqClient
from gnes.service.preprocessor import PreprocessorService


@@ -4,9 +4,9 @@
import numpy as np

from gnes.cli.parser import set_router_service_parser, _set_client_parser
from gnes.client.base import ZmqClient
from gnes.proto import gnes_pb2, array2blob
from gnes.service.base import SocketType
from gnes.service.grpc import ZmqClient
from gnes.service.router import RouterService


@@ -2,8 +2,8 @@
import unittest

from gnes.cli.parser import set_preprocessor_service_parser, _set_client_parser
from gnes.client.base import ZmqClient
from gnes.proto import gnes_pb2, RequestGenerator, blob2array
from gnes.service.grpc import ZmqClient
from gnes.service.preprocessor import PreprocessorService


@@ -2,8 +2,8 @@
import unittest

from gnes.cli.parser import set_preprocessor_service_parser, _set_client_parser
from gnes.client.base import ZmqClient
from gnes.proto import gnes_pb2, RequestGenerator, blob2array
from gnes.service.grpc import ZmqClient
from gnes.service.preprocessor import PreprocessorService


0 comments on commit 8516096

Please sign in to comment.
You can’t perform that action at this time.