@Override public void channelInactive(ChannelHandlerContext ctx) { activeChannels.remove(ctx); }
private void attachPublishCancelEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; } } registerMetaSet.remove(meta); }
private void deleteService(final ServiceDiscovery discovery, final Set<String> ids) { // Delete service from current zero system. Observable.fromIterable(ids) .subscribe(id -> { final String item = ID_MAP.get(id); discovery.unpublish(item, result -> { if (result.succeeded()) { // Delete successfully final Record record = REGISTRITIONS.get(id); this.successLog(record); // Sync deleted REGISTRITIONS.remove(id); ID_MAP.remove(id); // Remove from Set REGISTRY.remove(id); } else { LOGGER.info(Info.REG_FAILURE, result.cause().getMessage(), "Delete"); } }); }); }
private void deleteService(final ServiceDiscovery discovery, final Set<String> ids) { // Delete service from current zero system. Observable.fromIterable(ids) .subscribe(id -> { final String item = ID_MAP.get(id); discovery.unpublish(item, result -> { if (result.succeeded()) { // Delete successfully final Record record = REGISTRITIONS.get(id); this.successLog(record); // Sync deleted REGISTRITIONS.remove(id); ID_MAP.remove(id); // Remove from Set REGISTRY.remove(id); } else { LOGGER.info(Info.REG_FAILURE, result.cause().getMessage(), "Delete"); } }); }); }
@Override public void register(RegisterInfo registerInfo) { String parentPath = getParentRegisterPath(registerInfo); String path = getRegisterPath(registerInfo); String pathData = getRegisterPathData(registerInfo); try { if (client.checkExists().forPath(parentPath) == null) { client.create().withMode(CreateMode.PERSISTENT).forPath(parentPath); } client.create().withMode(CreateMode.EPHEMERAL).forPath(path, pathData.getBytes()); log.info("register success to {}", url); } catch (Exception ex) { if (!registerInfo.isIgnoreFailOfNamingService()) { throw new RpcException("Failed to register to " + url, ex); } else { failedRegisters.add(registerInfo); return; } } failedRegisters.remove(registerInfo); }
/** * Merges two laserRelayNetworks together * (Actually puts everything from the second network into the first one and removes the second one) */ private static void mergeNetworks(Network firstNetwork, Network secondNetwork, World world){ for(IConnectionPair secondPair : secondNetwork.connections){ firstNetwork.connections.add(secondPair); } WorldData data = WorldData.get(world); secondNetwork.changeAmount++; data.laserRelayNetworks.remove(secondNetwork); data.markDirty(); //System.out.println("Merged Two Networks!"); }
/*** * 服务下线的接口 * * @param meta * @param channel * @throws InterruptedException * @throws RemotingTimeoutException * @throws RemotingSendRequestException */ public void handlePublishCancel(RegisterMeta meta, Channel channel) throws RemotingSendRequestException, RemotingTimeoutException, InterruptedException { if (logger.isDebugEnabled()) { logger.info("Cancel publish {} on channel{}.", meta, channel); } //将其channel上打上的标记移除掉 attachPublishCancelEventOnChannel(meta, channel); final String serviceMeta = meta.getServiceName(); ConcurrentMap<Address, RegisterMeta> maps = this.getRegisterMeta(serviceMeta); if (maps.isEmpty()) { return; } synchronized (globalRegisterInfoMap) { Address address = meta.getAddress(); RegisterMeta data = maps.remove(address); if (data != null) { this.getServiceMeta(address).remove(serviceMeta); if (data.getIsReviewed() == ServiceReviewState.PASS_REVIEW ) this.defaultRegistryServer.getConsumerManager().notifyMacthedSubscriberCancel(meta); } } }
/** * Removes a Relay from its Network */ @Override public void removeRelayFromNetwork(BlockPos relay, World world){ Network network = this.getNetworkFor(relay, world); if(network != null){ network.changeAmount++; //Setup new network (so that splitting a network will cause it to break into two) WorldData data = WorldData.get(world); data.laserRelayNetworks.remove(network); data.markDirty(); for(IConnectionPair pair : network.connections){ if(!pair.contains(relay)){ this.addConnection(pair.getPositions()[0], pair.getPositions()[1], pair.getType(), world, pair.doesSuppressRender()); } } //System.out.println("Removing a Relay from the Network!"); } }
@Override public void removeConnection(World world, BlockPos firstRelay, BlockPos secondRelay){ if(world != null && firstRelay != null && secondRelay != null){ Network network = this.getNetworkFor(firstRelay, world); if(network != null){ network.changeAmount++; WorldData data = WorldData.get(world); data.laserRelayNetworks.remove(network); data.markDirty(); for(IConnectionPair pair : network.connections){ if(!pair.contains(firstRelay) || !pair.contains(secondRelay)){ this.addConnection(pair.getPositions()[0], pair.getPositions()[1], pair.getType(), world, pair.doesSuppressRender()); } } } } }
private CompletableFuture<Void> checkTxnStatus(Transaction<String> txn, int eventsWritten) { testState.committingTxn.add(txn.getTxnId()); return Retry.indefinitelyWithExpBackoff("Txn did not get committed").runAsync(() -> { Transaction.Status status = txn.checkStatus(); log.debug("Txn id {} status is {}", txn.getTxnId(), status); if (status.equals(Transaction.Status.COMMITTED)) { testState.incrementTotalWrittenEvents(eventsWritten); testState.committingTxn.remove(txn.getTxnId()); log.info("Event write count: {}", testState.getEventWrittenCount()); } else if (status.equals(Transaction.Status.ABORTED)) { log.debug("Transaction with id: {} aborted", txn.getTxnId()); testState.abortedTxn.add(txn.getTxnId()); } else { throw new TxnNotCompleteException(); } return CompletableFuture.completedFuture(null); }, executorService); }