private void initializeGateways(int concurrencyLevel) { // Create a GatewayImpl for each of the parallel threads for (int i = 0; i < concurrencyLevel; i++) { Gateway gateway = new GatewayImpl((GatewayHubImpl) getGatewayHub(), getId() + "." + i, true, getStatistics()); getGateways().add(gateway); } StringBuilder builder = new StringBuilder(); for (Iterator<Gateway> i = getGateways().iterator(); i.hasNext();) { Gateway gateway = i.next(); builder.append(gateway.getId()); if (i.hasNext()) { builder.append(", "); } } Object[] args = new Object[] {toString(), concurrencyLevel, builder.toString()}; getLogger().info(LocalizedStrings.GatewayParallel_0_CREATED_1_GATEWAYS_2, args); } }
public Gateway addGateway(String id, int concurrencyLevel) throws GatewayException { synchronized (this.controlLock) { checkRunning(); AbstractGateway gateway; synchronized (allGatewaysLock) { // If a gateway with the id is already defined, throw an exception if (alreadyDefinesGateway(id)) { throw new GatewayException(LocalizedStrings.GatewayHubImpl_GATEWAYHUB_0_ALREADY_DEFINES_A_GATEWAY_WITH_ID_1.toLocalizedString(new Object[] {this._id, id})); } if (concurrencyLevel < Gateway.DEFAULT_CONCURRENCY_LEVEL) { throw new GatewayException( LocalizedStrings.Gateway_INVALID_CONCURRENCY_LEVEL .toLocalizedString(new Object[] { id, concurrencyLevel })); } gateway = concurrencyLevel > Gateway.DEFAULT_CONCURRENCY_LEVEL ? new GatewayParallelImpl(this, id, concurrencyLevel) : new GatewayImpl(this, id); AbstractGateway snap[] = allGateways; // volatile fetch this.allGateways = (AbstractGateway[]) ArrayUtils.insert(snap, snap.length, gateway); this._gatewayIds.add(id); } this._statistics.incNumberOfGateways(); return gateway; } }