當前位置: 首頁>>代碼示例>>Java>>正文


Java DHTConfiguration類代碼示例

本文整理匯總了Java中lbms.plugins.mldht.DHTConfiguration的典型用法代碼示例。如果您正苦於以下問題:Java DHTConfiguration類的具體用法?Java DHTConfiguration怎麽用?Java DHTConfiguration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DHTConfiguration類屬於lbms.plugins.mldht包,在下文中一共展示了DHTConfiguration類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initKey

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
void initKey(DHTConfiguration config)
{
	if(config != null && config.isPersistingID()) {
		Path keyPath = config.getStoragePath().resolve("baseID.config");
		File keyFile = keyPath.toFile();
		
		if (keyFile.exists() && keyFile.isFile()) {
			try {
				List<String> raw = Files.readAllLines(keyPath);
				baseKey = raw.stream().map(String::trim).filter(Key.STRING_PATTERN.asPredicate()).findAny().map(Key::new).orElseThrow(() -> new IllegalArgumentException(keyPath.toString()+" did not contain valid node ID"));
				return;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	baseKey = Key.createRandomKey();
	
	persistKey();
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:22,代碼來源:Node.java

示例2: toMldhtConfig

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
private DHTConfiguration toMldhtConfig(DHTConfig config) {
    return new DHTConfiguration() {
        @Override
        public boolean isPersistingID() {
            return false;
        }

        @Override
        public Path getStoragePath() {
            return Files.createTempDir().toPath();
        }

        @Override
        public int getListeningPort() {
            return config.getListeningPort();
        }

        @Override
        public boolean noRouterBootstrap() {
            return true;
        }

        @Override
        public boolean allowMultiHoming() {
            return false;
        }

        @Override
        public Predicate<InetAddress> filterBindAddress() {
            return address -> {
                boolean bothAnyLocal = address.isAnyLocalAddress() && localAddress.isAnyLocalAddress();
                boolean couldUse = bothAnyLocal || localAddress.equals(address);
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Filtering addresses to bind DHT server to.. Checking " + address + ".. Could use: " + couldUse);
                }
                return couldUse;
            };
        }
    };
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:41,代碼來源:MldhtService.java

示例3: buildDHT

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
static DHT buildDHT(DHT.DHTtype type) {
	DHT dht = new DHT(type);
	dht.config = new DHTConfiguration() {
		
		@Override
		public boolean noRouterBootstrap() {
			// TODO Auto-generated method stub
			return false;
		}
		
		@Override
		public boolean isPersistingID() {
			// TODO Auto-generated method stub
			return false;
		}
		
		@Override
		public Path getStoragePath() {
			// TODO Auto-generated method stub
			return Paths.get(".", "does", "not", "exist");
		}
		
		@Override
		public int getListeningPort() {
			// TODO Auto-generated method stub
			return 0;
		}
		
		@Override
		public boolean allowMultiHoming() {
			// TODO Auto-generated method stub
			return false;
		}
	};
	dht.populate();
	
	return dht;
	
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:40,代碼來源:NodeFactory.java

示例4: getConfiguration

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
private static DHTConfiguration getConfiguration() {
    return new DHTConfiguration() {

        @Override
        public boolean noRouterBootstrap() {
            return false;
        }

        @Override
        public boolean isPersistingID() {
            return true;
        }

        @Override
        public File getNodeCachePath() {
            return new File("/tmp/dht");
        }

        @Override
        public int getListeningPort() {
            return 5556;
        }

        @Override
        public boolean allowMultiHoming() {
            return false;
        }
    };
}
 
開發者ID:Glamdring,項目名稱:scientific-publishing,代碼行數:30,代碼來源:DHTService.java

示例5: getConfig

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
public DHTConfiguration getConfig() {
	return config;
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:4,代碼來源:DHT.java

示例6: start

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
public void start (DHTConfiguration config)
		throws SocketException {
	if (running) {
		return;
	}
	
	if(this.scheduler == null)
		this.scheduler = getDefaultScheduler();
	this.config = config;
	useRouterBootstrapping = !config.noRouterBootstrap();
	
	if(!Files.isDirectory(config.getStoragePath()))
		DHT.log("Warning: storage path " + config.getStoragePath() +" is not a directory. DHT will not be able to persist state" , LogLevel.Info);
	
	table_file = config.getStoragePath().resolve(type.shortName+"-table.cache");

	setStatus(DHTStatus.Stopped, DHTStatus.Initializing);
	stats.resetStartedTimestamp();

	logInfo("Starting DHT on port " + getPort());

	// we need the IPs to filter bootstrap nodes out from the routing table. but don't block startup on DNS resolution
	scheduler.execute(this::resolveBootstrapAddresses);
	
	connectionManager = new NIOConnectionManager("mlDHT "+type.shortName+" NIO Selector");
	
	populate();
	
	node.initKey(config);
	node.loadTable(table_file);
	

	// these checks are fairly expensive on large servers (network interface enumeration)
	// schedule them separately
	scheduledActions.add(scheduler.scheduleWithFixedDelay(serverManager::doBindChecks, 10, 10, TimeUnit.SECONDS));
	
	scheduledActions.add(scheduler.scheduleWithFixedDelay(() -> {
		// maintenance that should run all the time, before the first queries
		tman.dequeue();

		if (running)
			onStatsUpdate();
	}, 5000, DHTConstants.DHT_UPDATE_INTERVAL, TimeUnit.MILLISECONDS));

	// initialize as many RPC servers as we need
	serverManager.refresh(System.currentTimeMillis());
	
	if(serverManager.getServerCount() == 0) {
		logError("No network interfaces eligible for DHT sockets found during startup."
				+ "\nAddress family: " + this.getType()
				+ "\nmultihoming [requires public IP addresses if enabled]: " + config.allowMultiHoming()
				+ "\nPublic IP addresses: " + AddressUtils.getAvailableGloballyRoutableAddrs(getType().PREFERRED_ADDRESS_TYPE)
				+ "\nDefault route: " + AddressUtils.getDefaultRoute(getType().PREFERRED_ADDRESS_TYPE));
	}
	
	started();

}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:59,代碼來源:DHT.java

示例7: persistKey

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
void persistKey() {
	DHTConfiguration config = dht.getConfig();
	
	if(config == null)
		return;
	
	Path keyPath = config.getStoragePath().resolve("baseID.config");
	
	try {
		if(!Files.isDirectory(config.getStoragePath()))
			return;
		Path tmpFile = Files.createTempFile(config.getStoragePath(), "baseID", ".tmp");
		
		Files.write(tmpFile, Collections.singleton(baseKey.toString(false)), StandardCharsets.ISO_8859_1);
		Files.move(tmpFile, keyPath, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
		
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
	
	
	
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:27,代碼來源:Node.java

示例8: testBindFilter

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
@Test
public void testBindFilter() {
	DHT dht = NodeFactory.buildDHT(DHTtype.IPV4_DHT);
	dht.getNode().initKey(null);
	dht.setScheduler(Executors.newSingleThreadScheduledExecutor());
	AtomicReference<Predicate<InetAddress>> predicate = new AtomicReference<>(null);
	
	dht.config = new DHTConfiguration() {
		
		@Override
		public boolean noRouterBootstrap() {
			return true;
		}
		
		@Override
		public boolean isPersistingID() {
			// TODO Auto-generated method stub
			return false;
		}
		
		@Override
		public Path getStoragePath() {
			// TODO Auto-generated method stub
			return null;
		}
		
		@Override
		public int getListeningPort() {
			// TODO Auto-generated method stub
			return 0;
		}
		
		@Override
		public boolean allowMultiHoming() {
			return false;
		}
		
		@Override
		public Predicate<InetAddress> filterBindAddress() {
			return predicate.get();
		}
	};
	
	predicate.set((unused) -> true);
	RPCServerManager srvman = dht.getServerManager();
	srvman.refresh(System.currentTimeMillis());
	assertNotEquals(0, srvman.getServerCount());
	
	predicate.set((unused) -> false);
	srvman.doBindChecks();
	assertEquals(0, srvman.getServerCount());
	
	// wildcard addr same as allowing all addresses of that family
	predicate.set((addr) -> addr instanceof Inet4Address && addr.isAnyLocalAddress());
	srvman.refresh(System.currentTimeMillis());
	assertNotEquals(0, srvman.getServerCount());
	
	// select a specific address
	InetAddress localAddr = AddressUtils.nonlocalAddresses().filter(Inet4Address.class::isInstance).findAny().get();
	predicate.set((addr) -> addr.equals(localAddr));
	srvman.doBindChecks();
	srvman.refresh(System.currentTimeMillis());
	assertEquals(localAddr, srvman.getAllServers().get(0).getBindAddress());
	
	
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:67,代碼來源:DHTLifeCycleTest.java

示例9: start

import lbms.plugins.mldht.DHTConfiguration; //導入依賴的package包/類
/**
 * Start the DHT
 */
void start (DHTConfiguration config) throws SocketException;
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:5,代碼來源:DHTBase.java


注:本文中的lbms.plugins.mldht.DHTConfiguration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。