Search in sources :

Example 6 with AppMetadata

use of org.kin.rsocket.core.metadata.AppMetadata in project kin-rsocket-broker by huangjianqin.

the class DiscoveryServiceImpl method newServiceInstance.

/**
 * 构建{@link RSocketServiceInstance}实例
 */
private RSocketServiceInstance newServiceInstance(RSocketEndpoint rsocketEndpoint) {
    AppMetadata appMetadata = rsocketEndpoint.getAppMetadata();
    RSocketServiceInstance serviceInstance = new RSocketServiceInstance();
    serviceInstance.setInstanceId(appMetadata.getUuid());
    serviceInstance.setServiceId(appMetadata.getName());
    serviceInstance.setHost(appMetadata.getIp());
    if (appMetadata.getWebPort() > 0) {
        serviceInstance.setPort(appMetadata.getWebPort());
        String schema = "http";
        serviceInstance.setSecure(appMetadata.isSecure());
        // todo 返回https时, http gate抛异常
        // if (appMetadata.isSecure()) {
        // schema = "https";
        // }
        serviceInstance.setSchema(schema);
        // 返回web port
        serviceInstance.setUri(schema + "://" + appMetadata.getIp() + ":" + appMetadata.getWebPort());
    }
    serviceInstance.setMetadata(appMetadata.getMetadata());
    return serviceInstance;
}
Also used : RSocketServiceInstance(org.kin.rsocket.core.discovery.RSocketServiceInstance) AppMetadata(org.kin.rsocket.core.metadata.AppMetadata)

Example 7 with AppMetadata

use of org.kin.rsocket.core.metadata.AppMetadata in project kin-rsocket-broker by huangjianqin.

the class RSocketServiceManager method updateP2pServiceConsumers.

/**
 * 更新指定app应用开启的p2p服务gsv
 */
public void updateP2pServiceConsumers(String appId, Set<String> p2pServiceIds) {
    RSocketEndpoint rsocketEndpoint = getByUUID(appId);
    if (rsocketEndpoint != null) {
        AppMetadata appMetadata = rsocketEndpoint.getAppMetadata();
        Integer instanceId = rsocketEndpoint.getId();
        appMetadata.updateP2pServiceIds(p2pServiceIds);
        Lock writeLock = lock.writeLock();
        writeLock.lock();
        try {
            // copy on write
            UnifiedSetMultimap<String, Integer> p2pServiceConsumers = new UnifiedSetMultimap<>(this.p2pServiceConsumers);
            for (String p2pService : appMetadata.getP2pServiceIds()) {
                p2pServiceConsumers.put(p2pService, instanceId);
                rsocketEndpoint.fireCloudEvent(newServiceInstanceChangedCloudEvent(p2pService)).subscribe();
            }
            this.p2pServiceConsumers = p2pServiceConsumers;
        } finally {
            writeLock.unlock();
        }
    }
}
Also used : UnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap) AppMetadata(org.kin.rsocket.core.metadata.AppMetadata) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

AppMetadata (org.kin.rsocket.core.metadata.AppMetadata)7 Lock (java.util.concurrent.locks.Lock)3 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)3 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 UnifiedSetMultimap (org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap)3 UnifiedMap (org.eclipse.collections.impl.map.mutable.UnifiedMap)2 FastListMultimap (org.eclipse.collections.impl.multimap.list.FastListMultimap)2 RSocketEndpoint (org.kin.rsocket.broker.RSocketEndpoint)2 ApplicationErrorException (io.rsocket.exceptions.ApplicationErrorException)1 RejectedSetupException (io.rsocket.exceptions.RejectedSetupException)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 RSocketAppPrincipal (org.kin.rsocket.auth.RSocketAppPrincipal)1 RSocketServiceInstance (org.kin.rsocket.core.discovery.RSocketServiceInstance)1 AppVO (org.kin.rsocket.core.domain.AppVO)1 BearerTokenMetadata (org.kin.rsocket.core.metadata.BearerTokenMetadata)1 RSocketCompositeMetadata (org.kin.rsocket.core.metadata.RSocketCompositeMetadata)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1