Search in sources :

Example 1 with Transport

use of org.apache.servicecomb.core.Transport in project incubator-servicecomb-java-chassis by apache.

the class AbstractEndpointsCache method createEndpoints.

protected List<ENDPOINT> createEndpoints(Map<String, List<CacheEndpoint>> transportMap) {
    List<ENDPOINT> tmpEndpoints = new ArrayList<>();
    for (Entry<String, List<CacheEndpoint>> entry : transportMap.entrySet()) {
        Transport transport = transportManager.findTransport(entry.getKey());
        if (transport == null) {
            continue;
        }
        List<CacheEndpoint> endpointList = entry.getValue();
        if (endpointList == null) {
            continue;
        }
        for (CacheEndpoint cacheEndpoint : endpointList) {
            ENDPOINT endpoint = createEndpoint(transport, cacheEndpoint);
            tmpEndpoints.add(endpoint);
        }
    }
    return tmpEndpoints;
}
Also used : CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Transport(org.apache.servicecomb.core.Transport)

Example 2 with Transport

use of org.apache.servicecomb.core.Transport in project incubator-servicecomb-java-chassis by apache.

the class TransportManager method groupByName.

protected Map<String, List<Transport>> groupByName() {
    Map<String, List<Transport>> groups = new HashMap<>();
    for (Transport transport : transports) {
        List<Transport> list = groups.computeIfAbsent(transport.getName(), name -> {
            return new ArrayList<>();
        });
        list.add(transport);
    }
    return groups;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Transport(org.apache.servicecomb.core.Transport)

Example 3 with Transport

use of org.apache.servicecomb.core.Transport in project incubator-servicecomb-java-chassis by apache.

the class TransportManager method buildTransportMap.

protected void buildTransportMap() {
    Map<String, List<Transport>> groups = groupByName();
    for (Entry<String, List<Transport>> entry : groups.entrySet()) {
        List<Transport> group = entry.getValue();
        checkTransportGroup(group);
        Transport transport = chooseOneTransport(group);
        transportMap.put(transport.getName(), transport);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Transport(org.apache.servicecomb.core.Transport)

Example 4 with Transport

use of org.apache.servicecomb.core.Transport in project incubator-servicecomb-java-chassis by apache.

the class TransportManager method init.

public void init() throws Exception {
    buildTransportMap();
    for (Transport transport : transportMap.values()) {
        if (transport.init()) {
            Endpoint endpoint = transport.getPublishEndpoint();
            if (endpoint != null && endpoint.getEndpoint() != null) {
                LOGGER.info("endpoint to publish: {}", endpoint.getEndpoint());
                Microservice microservice = RegistryUtils.getMicroservice();
                microservice.getInstance().getEndpoints().add(endpoint.getEndpoint());
            }
            continue;
        }
    }
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Endpoint(org.apache.servicecomb.core.Endpoint) Transport(org.apache.servicecomb.core.Transport)

Example 5 with Transport

use of org.apache.servicecomb.core.Transport in project incubator-servicecomb-java-chassis by apache.

the class TransportClientHandler method handle.

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    Transport transport = invocation.getTransport();
    log.debug("Sending request {} to {}", invocation.getMicroserviceQualifiedName(), invocation.getEndpoint().getEndpoint());
    transport.send(invocation, asyncResp);
}
Also used : Transport(org.apache.servicecomb.core.Transport)

Aggregations

Transport (org.apache.servicecomb.core.Transport)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CacheEndpoint (org.apache.servicecomb.serviceregistry.cache.CacheEndpoint)2 LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)1 Server (com.netflix.loadbalancer.Server)1 HashMap (java.util.HashMap)1 Endpoint (org.apache.servicecomb.core.Endpoint)1 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)1 Test (org.junit.Test)1