当前位置: 首页>>代码示例>>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;未经允许,请勿转载。