当前位置: 首页>>代码示例>>Java>>正文


Java FileConfiguration类代码示例

本文整理汇总了Java中org.hive2hive.core.api.configs.FileConfiguration的典型用法代码示例。如果您正苦于以下问题:Java FileConfiguration类的具体用法?Java FileConfiguration怎么用?Java FileConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileConfiguration类属于org.hive2hive.core.api.configs包,在下文中一共展示了FileConfiguration类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createNode

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
private IH2HNode createNode() throws UnknownHostException {
	InetAddress bootstrapAddress = InetAddress.getByName(BOOTSTRAP_HOST_NAME); // InetAddress.getLocalHost();
	INetworkConfiguration networkConf = null;
	if (IS_INITIAL_NODE) {
		networkConf = NetworkConfiguration.createInitial("node-"
				+ BOOTSTRAP_HOST_NAME + "-" + NODE_NAME);
	} else {
		networkConf = NetworkConfiguration.create("node-"
				+ BOOTSTRAP_HOST_NAME + "-" + NODE_NAME,
				bootstrapAddress);
	}

	FSTSerializer serializer = new FSTSerializer();
	IH2HNode node = H2HNode.createNode(FileConfiguration.createDefault(), new H2HDummyEncryption(), serializer);
	node.connect(networkConf);
	return node;
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:18,代码来源:ClientStarter.java

示例2: testIsSmallFile

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
@Test
public void testIsSmallFile() throws IOException {
	IFileConfiguration fileConf = FileConfiguration.createDefault();
	Mockito.stub(nodeManager.getFileConfiguration()).toReturn(fileConf);

	int size = -1 + fileConf.getMaxFileSize().intValue();
	String content = RandomStringUtils.randomAlphanumeric(size);
	Path smallFile = rootPath.resolve("smallFile.txt");
	FileUtils.writeStringToFile(smallFile.toFile(), content);

	assertTrue(fileManager.isSmallFile(smallFile));
	assertFalse(fileManager.isLargeFile(smallFile));

	Files.deleteIfExists(smallFile);
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:16,代码来源:FileManagerTest.java

示例3: testIsLargeFile

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
@Test
public void testIsLargeFile() throws IOException {
	IFileConfiguration fileConf = FileConfiguration.createDefault();
	Mockito.stub(nodeManager.getFileConfiguration()).toReturn(fileConf);

	int size = 1 + fileConf.getMaxFileSize().intValue();
	String content = RandomStringUtils.randomAlphanumeric(size);
	Path largeFile = rootPath.resolve("smallFile.txt");
	FileUtils.writeStringToFile(largeFile.toFile(), content);

	assertFalse(fileManager.isSmallFile(largeFile));
	assertTrue(fileManager.isLargeFile(largeFile));

	Files.deleteIfExists(largeFile);
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:16,代码来源:FileManagerTest.java

示例4: main

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
public static void main(String[] args) throws UnknownHostException {
	// Create a consistent file configuration for all nodes
	IFileConfiguration fileConfiguration = FileConfiguration.createDefault();

	// Initialize several nodes (not connected yet)
	IH2HNode node1 = H2HNode.createNode(fileConfiguration);
	IH2HNode node2 = H2HNode.createNode(fileConfiguration);
	IH2HNode node3 = H2HNode.createNode(fileConfiguration);
	IH2HNode node4 = H2HNode.createNode(fileConfiguration);

	// Create a new P2P network at the first (initial) peer
	node1.connect(NetworkConfiguration.createInitial());

	// Connect the 2nd peer to the network. This peer bootstraps to node1 running at the local host
	NetworkConfiguration node2Conf = NetworkConfiguration.create(InetAddress.getLocalHost());
	node2.connect(node2Conf);

	// The network configuration builder allows you to configure more details
	// here we set a custom (non-random) node id and a custom port that the node 3 binds to
	NetworkConfiguration node3Conf = NetworkConfiguration.create(InetAddress.getLocalHost()).setPort(4777)
			.setNodeId("node3");
	node3.connect(node3Conf);

	// Nodes can bootstrap to any of the connected peers. Therefore, we set that node4 should connect to
	// node3 to become a part of the P2P network
	NetworkConfiguration node4Conf = NetworkConfiguration.create(InetAddress.getLocalHost()).setBootstrapPort(4777);
	node4.connect(node4Conf);

	// We can test the connection status of these nodes
	System.out.println("Node 1 is connected: " + node1.isConnected());
	System.out.println("Node 2 is connected: " + node2.isConnected());
	System.out.println("Node 3 is connected: " + node3.isConnected());
	System.out.println("Node 4 is connected: " + node4.isConnected());
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:35,代码来源:ConnectExample.java

示例5: main

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
public static void main(String[] args) throws NoPeerConnectionException, InvalidProcessStateException,
		ProcessExecutionException {
	// Create a node and open a new overlay network
	IH2HNode node = H2HNode.createNode(FileConfiguration.createDefault());
	node.connect(NetworkConfiguration.createInitial());

	// The register functionality is in the user manager API
	IUserManager userManager = node.getUserManager();

	// Create user credentials to register a new user 'Alice'
	UserCredentials alice = new UserCredentials("Alice", "very-secret-password", "secret-pin");

	// Create a new register process and start it (blocking)
	IProcessComponent<Void> registerAlice = userManager.createRegisterProcess(alice);
	registerAlice.execute();

	// Check if Alice is now registered
	boolean aliceRegistered = userManager.isRegistered("Alice");
	System.out.println("Alice is registered: " + aliceRegistered);

	// Let's login to Alice's user account (blocking)
	IProcessComponent<Void> loginAlice = userManager.createLoginProcess(alice, new ExampleFileAgent());
	loginAlice.execute();

	// Check if Alice is now logged in
	System.out.println("Alice is logged in: " + userManager.isLoggedIn());
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:28,代码来源:RegisterLoginExample.java

示例6: main

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	IFileConfiguration fileConfiguration = FileConfiguration.createDefault();

	// Create two nodes and open a new overlay network
	IH2HNode node1 = H2HNode.createNode(fileConfiguration);
	IH2HNode node2 = H2HNode.createNode(fileConfiguration);
	node1.connect(NetworkConfiguration.createInitial());
	node2.connect(NetworkConfiguration.create(InetAddress.getLocalHost()));

	// These two file agents are used to configure the root directory of the logged in user
	ExampleFileAgent node1FileAgent = new ExampleFileAgent();
	ExampleFileAgent node2FileAgent = new ExampleFileAgent();

	// Register user 'Alice' and login her at node 1 and 2
	UserCredentials alice = new UserCredentials("Alice", "password", "pin");
	node1.getUserManager().createRegisterProcess(alice).execute();
	node1.getUserManager().createLoginProcess(alice, node1FileAgent).execute();
	node2.getUserManager().createLoginProcess(alice, node2FileAgent).execute();

	// In this example, a file event listener is registered at node 2. Therefore, we will listen to events
	// that happen by actions taken by node 1.
	node2.getFileManager().subscribeFileEvents(new ExampleEventListener(node2.getFileManager()));

	// To demonstrate the 'add' event, we will add a new file with node 1
	// Let's create a file and upload it at node 1
	File fileAtNode1 = new File(node1FileAgent.getRoot(), "test-file-event.txt");
	FileUtils.write(fileAtNode1, "Hello"); // add some content
	node1.getFileManager().createAddProcess(fileAtNode1).execute();

	// Let's trigger a deletion event
	fileAtNode1.delete();
	node1.getFileManager().createDeleteProcess(fileAtNode1).execute();
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:34,代码来源:EventsExample.java

示例7: getPeer

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
@Test
public void getPeer() {
	// a unconnected node does not provide a peer
	IFileConfiguration fileConfig = FileConfiguration.createDefault();
	IH2HNode node = H2HNode.createNode(fileConfig);
	Assert.assertNull(node.getPeer());

	// connected nodes return a peer
	for (IH2HNode connectedNode : network) {
		Assert.assertNotNull(connectedNode.getPeer());
	}
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:13,代码来源:H2HNodeTest.java

示例8: createNode

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
private synchronized void createNode() {
	fileConfiguration = FileConfiguration.createDefault();
	node = H2HNode.createNode(fileConfiguration);
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:5,代码来源:NodeManager.java

示例9: main

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
public static void main(String[] args) {
	try {

		INetworkConfiguration netConfig = null;

		if (args.length == 0) {

			// initial peer
			netConfig = NetworkConfiguration.createInitial();
			logger.info("Start as initial peer");

		} else if (args.length >= 1) {

			// connect to node
			String nodeId = UUID.randomUUID().toString();
			InetAddress address = InetAddress.getByName(args[0]);
			netConfig = NetworkConfiguration.create(nodeId, address);
			logger.info("Connect to existing peer. Address: {}", address.toString());

		}

		IFileConfiguration fileConfig = FileConfiguration.createDefault();
		IH2HNode peerNode = H2HNode.createNode(fileConfig);
		boolean success = peerNode.connect(netConfig);

		if (success) {
			logger.info("Setup successful.");
		} else {
			logger.error("Could not setup node.");
			System.exit(-1);
		}

		// do not exit
		logger.info("Finished creating node.");
		Thread.currentThread().join();

	} catch (Exception e) {
		logger.warn("Exception: {}", e.getMessage(), e);
	}

}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:42,代码来源:NodeStarter.java

示例10: main

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	IFileConfiguration fileConfiguration = FileConfiguration.createDefault();

	// Create two nodes and open a new overlay network
	IH2HNode node1 = H2HNode.createNode(fileConfiguration);
	IH2HNode node2 = H2HNode.createNode(fileConfiguration);
	node1.connect(NetworkConfiguration.createInitial());
	node2.connect(NetworkConfiguration.create(InetAddress.getLocalHost()));

	// These two file agents are used to configure the root directory of the logged in users
	ExampleFileAgent node1FileAgent = new ExampleFileAgent();
	ExampleFileAgent node2FileAgent = new ExampleFileAgent();

	// Register and login user 'Alice' at node 1
	UserCredentials alice = new UserCredentials("Alice", "password", "pin");
	node1.getUserManager().createRegisterProcess(alice).execute();
	node1.getUserManager().createLoginProcess(alice, node1FileAgent).execute();

	// Register and login user 'Bob' at node 2
	UserCredentials bob = new UserCredentials("Bob", "password", "pin");
	node2.getUserManager().createRegisterProcess(bob).execute();
	node2.getUserManager().createLoginProcess(bob, node2FileAgent).execute();

	// Let's create a folder at Alice and upload it
	IFileManager fileManager1 = node1.getFileManager(); // The file management of Alice's peer
	File folderAtAlice = new File(node1FileAgent.getRoot(), "shared-folder");
	folderAtAlice.mkdirs();
	fileManager1.createAddProcess(folderAtAlice).execute();

	// Let's share the folder with Bob giving him write permission
	fileManager1.createShareProcess(folderAtAlice, "Bob", PermissionType.WRITE).execute();

	// Wait some time in order to get the file share event propagated to Bob
	System.out.println("Alice shared a folder with Bob. We'll wait some time for its propagation...");
	Thread.sleep(20000);

	// Bob can now 'download' the folder (yes, sounds a little bit silly...)
	IFileManager fileManager2 = node2.getFileManager(); // The file management of Bob's peer
	File folderAtBob = new File(node2FileAgent.getRoot(), "shared-folder");
	fileManager2.createDownloadProcess(folderAtBob).execute();

	// Bob could for example upload a new file to the shared folder
	File fileAtBob = new File(folderAtBob, "shared-file.txt");
	FileUtils.write(fileAtBob, "This is a shared file of Alice and Bob");
	fileManager2.createAddProcess(fileAtBob).execute();

	// Wait some time in order to get the file share event propagated to Bob
	System.out.println("Waiting that Alice sees the file from Bob...");
	Thread.sleep(20000);

	// Alice now can obtain the shared file
	File fileAtAlice = new File(folderAtAlice, "shared-file.txt");
	fileManager1.createDownloadProcess(fileAtAlice).execute();
	System.out.println("Content of the file in the shared folder at Alice: " + FileUtils.readFileToString(fileAtAlice));
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:56,代码来源:ShareExample.java

示例11: main

import org.hive2hive.core.api.configs.FileConfiguration; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	IFileConfiguration fileConfiguration = FileConfiguration.createDefault();

	// Create two nodes and open a new overlay network
	IH2HNode node1 = H2HNode.createNode(fileConfiguration);
	IH2HNode node2 = H2HNode.createNode(fileConfiguration);
	node1.connect(NetworkConfiguration.createInitial());
	node2.connect(NetworkConfiguration.create(InetAddress.getLocalHost()));

	// These two file agents are used to configure the root directory of the logged in users
	ExampleFileAgent node1FileAgent = new ExampleFileAgent();
	ExampleFileAgent node2FileAgent = new ExampleFileAgent();

	// Register and login user 'Alice' at node 1
	UserCredentials alice = new UserCredentials("Alice", "password", "pin");
	node1.getUserManager().createRegisterProcess(alice).execute();
	node1.getUserManager().createLoginProcess(alice, node1FileAgent).execute();

	// Also login user 'Alice' at node 2
	node2.getUserManager().createLoginProcess(alice, node2FileAgent).execute();

	// All file management operations are located at the file manager. Here we get the file managers of
	// each peer alice is connected to.
	IFileManager fileManager1 = node1.getFileManager(); // for node 1
	IFileManager fileManager2 = node2.getFileManager(); // for node 2

	// Let's create a file and upload it at node 1
	File fileAtNode1 = new File(node1FileAgent.getRoot(), "test-file.txt");
	FileUtils.write(fileAtNode1, "Hello"); // add some content
	fileManager1.createAddProcess(fileAtNode1).execute();

	// Normally, the node 2 would be notified about the new file through the event bus (shown in another
	// example). However, we just know that the file exists in the network and can download it at node 2.
	// This is only possible because Alice is logged in into node 2 as well.
	File fileAtNode2 = new File(node2FileAgent.getRoot(), "test-file.txt");
	// this file does not exist yet (as we did not start the download process yet)
	System.out.println("Existence of the file prior to download: " + fileAtNode2.exists());
	fileManager2.createDownloadProcess(fileAtNode2).execute();

	// We can now re-check whether the file exists or not
	System.out.println("Existence of the file after download: " + fileAtNode2.exists());
	System.out.println("Content of the first version at node 2: " + FileUtils.readFileToString(fileAtNode2));

	// Now, let's modify the file at node 2 and re-upload a new version of it
	FileUtils.write(fileAtNode2, " World!", true); // append the text
	fileManager2.createUpdateProcess(fileAtNode2).execute();

	// The file has now updated, therefore we should download the new version at node 1
	fileManager1.createDownloadProcess(fileAtNode1).execute();
	System.out.println("Content of the second version at node 1: " + FileUtils.readFileToString(fileAtNode1));
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:52,代码来源:FileManagementExample.java


注:本文中的org.hive2hive.core.api.configs.FileConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。