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


Java NoPeerConnectionException类代码示例

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


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

示例1: execute

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@Override
public ExecutionHandle execute(IFileManager fileManager) throws NoSessionException, NoPeerConnectionException, InvalidProcessStateException, ProcessExecutionException {
	final Path path = action.getFile().getPath();
	logger.debug("Execute REMOTE UPDATE, download the file: {}", path);

	handle = fileManager.download(path);
	if (handle != null && handle.getProcess() != null) {
		FileInfo file = new FileInfo(action.getFile());
		handle.getProcess().attachListener(new RemoteFileUpdateListener(file, action.getFileEventManager().getMessageBus()));
		handle.executeAsync();
	} else {
		logger.warn("process or handle is null");
	}

	return new ExecutionHandle(action, handle);
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:17,代码来源:RemoteUpdateState.java

示例2: execute

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@Override
	public ExecutionHandle execute(IFileManager fileManager) throws NoSessionException, NoPeerConnectionException, ProcessExecutionException, InvalidProcessStateException {

		final Path path = action.getFile().getPath();
		handle = fileManager.move(source, path);
		if(handle != null){
			FileInfo destFile = new FileInfo(action.getFile());
			FileInfo sourceFile = new FileInfo(source, action.getFile().isFolder());
			handle.getProcess().attachListener(new LocalFileMoveListener(sourceFile, destFile, action.getFileEventManager().getMessageBus()));
			handle.executeAsync();
		}

		String contentHash = action.getFile().getContentHash();
//		Path pathToRemove = action.getFile().getPath();
		IFileTree fileTree = action.getFileEventManager().getFileTree();
		boolean isRemoved = fileTree.getCreatedByContentHash().get(contentHash).remove(action.getFile());
		logger.trace("IsRemoved for file {} with hash {}: {}", action.getFile().getPath(), contentHash, isRemoved);


		logger.debug("Task \"Move File\" executed from: " + source.toString()  + " to " + path.toString());
		return new ExecutionHandle(action, handle);
	}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:23,代码来源:LocalMoveState.java

示例3: execute

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
/**
 * If the create state is considered as stable, the execute method will be invoked which eventually
 * uploads the file with the corresponding Hive2Hive method
 *
 * @param file The file which should be uploaded
 * @return
 * @return
 * @throws ProcessExecutionException
 * @throws InvalidProcessStateException
 * @throws NoPeerConnectionException
 * @throws NoSessionException
 */
@Override
public ExecutionHandle execute(IFileManager fileManager) throws InvalidProcessStateException,
		ProcessExecutionException, NoSessionException, NoPeerConnectionException {

	final FileComponent file = action.getFile();
	final Path path = file.getPath();
	final MessageBus messageBus = action.getFileEventManager().getMessageBus();

	logger.debug("Execute LOCAL CREATE: {}", path);

	handle = fileManager.add(path);
	if (handle != null && handle.getProcess() != null) {
		FileInfo helper = new FileInfo(file);
		handle.getProcess().attachListener(new LocalFileAddListener(helper, messageBus));
		handle.executeAsync();
	} else {
		logger.warn("process or handle is null");
	}

	String contentHash = action.getFile().getContentHash();
	IFileTree fileTree = action.getFileEventManager().getFileTree();
	fileTree.getCreatedByContentHash().get(contentHash).remove(action.getFile());

	return new ExecutionHandle(action, handle);
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:38,代码来源:LocalCreateState.java

示例4: registerUser

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@Override
public synchronized ResultStatus registerUser(final String username, final String password, final String pin)
		throws NoPeerConnectionException {

	logger.debug("REGISTER - Username: {}", username);

	ResultStatus res = ResultStatus.error("Could not register user.");

	UserCredentials credentials = new UserCredentials(username, password, pin);

	try {

		IProcessComponent<Void> registerProc = getH2HUserManager().createRegisterProcess(credentials);
		registerProc.execute();
		if (isRegistered(credentials.getUserId())) {
			res = ResultStatus.ok();
			notifyRegister(username);
		}

	} catch (ProcessExecutionException | InvalidProcessStateException pex) {
		logger.warn("Register process failed (user={})", username, pex);
	}

	return res;
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:26,代码来源:UserManager.java

示例5: validateUsername

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
public static ValidationResult validateUsername(final String username, boolean checkIfRegistered, final IUserManager userManager) throws NoPeerConnectionException {
	if(username == null) {
		throw new IllegalArgumentException("Argument username must not be null.");
	}
	if(checkIfRegistered && userManager == null) {
		throw new IllegalArgumentException("Argument userManager must not be null if checkIfRegistered is true");
	}
	
	if(username.trim().isEmpty()) {
		return ValidationResult.USERNAME_EMPTY;
	}
	
	if(checkIfRegistered && userManager != null) {
		if(userManager.isRegistered(username)) {
			return ValidationResult.USERNAME_ALREADY_TAKEN;
		}
	}
	
	return ValidationResult.OK;
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:21,代码来源:ValidationUtils.java

示例6: validateUserExists

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
public static ValidationResult validateUserExists(final String username, boolean checkIfRegistered, final IUserManager userManager) throws NoPeerConnectionException {
	if(username == null) {
		throw new IllegalArgumentException("Argument username must not be null.");
	}
	if(checkIfRegistered && userManager == null) {
		throw new IllegalArgumentException("Argument userManager must not be null if checkIfRegistered is true.");
	}
	
	if(username.trim().isEmpty()) {
		return ValidationResult.USERNAME_EMPTY;
	}
	
	if(checkIfRegistered && userManager != null) {
		if(!userManager.isRegistered(username)) {
			return ValidationResult.USER_NOT_EXISTS;
		}
	}
	
	return ValidationResult.OK;
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:21,代码来源:ValidationUtils.java

示例7: validate

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
public ValidationResult validate(final String username, boolean checkIfRegistered) {
	try {

		if(username == null) {
			return ValidationResult.ERROR;
		}

		final String usernameTr = username.trim();
		ValidationResult res = ValidationUtils.validateUserExists(usernameTr, checkIfRegistered, userManager);

		if (res.isError()) {
			setErrorMessage(res.getMessage());
			decorateError();
		} else {
			clearErrorMessage();
			undecorateError();
		}

		return res;

	} catch (NoPeerConnectionException e) {
		setErrorMessage("Network connection failed.");
	}

	return ValidationResult.ERROR;
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:27,代码来源:UsernameRegisteredValidator.java

示例8: loginAction

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@FXML
public void loginAction(ActionEvent event) {
	boolean inputValid = false;
	try {
		clearError();
		ValidationResult validationRes = validateAll();
		inputValid = !validationRes.isError() && checkUserExists();
	} catch (NoPeerConnectionException e) {
		inputValid = false;
		setError("Connection to the network failed.");
	}

	if (inputValid) {
		Task<ResultStatus> task = createLoginTask();
		new Thread(task).start();
	}
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:18,代码来源:LoginController.java

示例9: testAlreadyRegistered

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@Test
public void testAlreadyRegistered() throws NoPeerConnectionException {

	// register
	ResultStatus res = client.getUserManager().registerUser(
			userCredentials.getUserId(), userCredentials.getPassword(), userCredentials.getPin());
	assertTrue(res.isOk());

	// got event?
	Mockito.verify(client.getMessageBus(), Mockito.times(1)).publish(Mockito.anyObject());

	// try register -- should fail
	for (int i = 0; i < network.size(); ++i) {
		ClientContext cc = createClientContext(network.get(i));
		IUserManager usrMgr = cc.getUserManager();
		res = usrMgr.registerUser(userCredentials.getUserId(), userCredentials.getPassword(), userCredentials.getPin());
		assertTrue(res.isError());

		// got NO event?
		Mockito.verify(cc.getMessageBus(), Mockito.never()).publish(Mockito.anyObject());
	}
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:23,代码来源:UserManagerTest.java

示例10: testLogin

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@Test
public void testLogin() throws NoPeerConnectionException, IOException {
	IUserManager userManager = client.getUserManager();
	// not loggedIn
	assertFalse(userManager.isLoggedIn());

	// register
	ResultStatus res = userManager.registerUser(userCredentials.getUserId(), userCredentials.getPassword(), userCredentials.getPin());
	assertTrue(res.isOk());
	assertFalse(userManager.isLoggedIn());
	// got event?
	Mockito.verify(client.getMessageBus(), Mockito.times(1)).publish(Mockito.any());

	// login and loggedIn
	res = userManager.loginUser(userCredentials.getUserId(), userCredentials.getPassword(), userCredentials.getPin(), root);
	assertTrue(res.isOk());
	assertTrue(userManager.isLoggedIn());

	// got event?
	ArgumentCaptor<LoginMessage> event = ArgumentCaptor.forClass(LoginMessage.class);
	Mockito.verify(client.getMessageBus(), Mockito.times(2)).publish(event.capture());
	assertNotNull(event.getValue());
	assertEquals(userCredentials.getUserId(), event.getValue().getUsername());
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:25,代码来源:UserManagerTest.java

示例11: testLogout

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@Test
public void testLogout() throws NoPeerConnectionException, IOException, NoSessionException {
	// register and login
	testLogin();
	IUserManager userManager = client.getUserManager();

	assertTrue(userManager.isLoggedIn());
	ResultStatus res = userManager.logoutUser();
	assertTrue(res.isOk());
	assertFalse(userManager.isLoggedIn());

	// got event? (Register, login, logout)
	ArgumentCaptor<LogoutMessage> event = ArgumentCaptor.forClass(LogoutMessage.class);
	Mockito.verify(client.getMessageBus(), Mockito.times(3)).publish(event.capture());
	assertNotNull(event.getValue());
	assertEquals(userCredentials.getUserId(), event.getValue().getUsername());
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:18,代码来源:UserManagerTest.java

示例12: testRecover

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@Test
public void testRecover() throws NoSessionException, NoPeerConnectionException {
	Mockito.stub(h2hFileManager.createRecoverProcess(any(), any())).toReturn(process);
	IVersionSelector version = new IVersionSelector() {
		@Override
		public IFileVersion selectVersion(List<IFileVersion> availableVersions) {
			return null;
		}
		@Override
		public String getRecoveredFileName(String fullName, String name, String extension) {
			return null;
		}
	};

	ProcessHandle<Void> p = fileManager.recover(file, version);
	assertNotNull(p);
	assertNotNull(p.getProcess());
	assertEquals(process, p.getProcess());

	Mockito.verify(h2hFileManager,  times(1)).createRecoverProcess(file.toFile(), version);
	Mockito.verifyNoMoreInteractions(h2hFileManager);
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:23,代码来源:FileManagerTest.java

示例13: initNetwork

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
private void initNetwork() throws NoPeerConnectionException, InvalidProcessStateException, ProcessExecutionException {
	// setup network and node
	network = NetworkTestUtil.createNetwork(NETWORK_SIZE);
	userCredentials = H2HJUnitTest.generateRandomCredentials();
	nodeManager = network.get(RandomUtils.nextInt(0, network.size()));;

	// user config
	root = FileTestUtil.getTempDirectory();
	userConfig = Mockito.mock(UserConfig.class);
	Mockito.stub(userConfig.getRootPath()).toReturn(root.toPath());

	// register and login
	userManager = new UserManager(nodeManager, messageBus);
	userManager.registerUser(userCredentials.getUserId(), userCredentials.getPassword(), userCredentials.getPin());
	userManager.loginUser(userCredentials.getUserId(), userCredentials.getPassword(), userCredentials.getPin(), root.toPath());
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:17,代码来源:FileRecoveryStarter.java

示例14: uploadFileVersions

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
private void uploadFileVersions() throws IOException, NoSessionException, NoPeerConnectionException, InvalidProcessStateException, ProcessExecutionException, IllegalArgumentException, InterruptedException {
	fileManager = new FileManager(nodeManager, userConfig);

	content = new ArrayList<String>();

	// add an initial file to the network
	file = new File(root, fileName);
	String fileContent = RandomStringUtils.randomAscii(FILE_SIZE);
	content.add(fileContent);
	FileUtils.write(file, fileContent);
	nodeManager.getNode().getFileManager().createAddProcess(file).execute();

	// update and upload
	int fileSize = FILE_SIZE;
	for(int i = 0; i < NUM_VERSIONS; ++i) {
		Thread.sleep(2000); // sleep such that each file has different timestamp
		fileSize *= INCREASE_FACTOR;
		fileContent = RandomStringUtils.randomAscii(fileSize);
		content.add(fileContent);
		FileUtils.write(file, fileContent);
		nodeManager.getNode().getFileManager().createUpdateProcess(file).execute();
	}
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:24,代码来源:FileRecoveryStarter.java

示例15: testCancel

import org.hive2hive.core.exceptions.NoPeerConnectionException; //导入依赖的package包/类
@Test
public void testCancel() throws NoSessionException, NoPeerConnectionException, InvalidProcessStateException, ProcessExecutionException {
	// count number of files to make sure no file recovered
	int numElementsBefore = root.list().length;

	// recover version and cancel
	FileVersionSelectorListener versionSelectorListener = new FileVersionSelectorListener(file.toPath(), -1);
	try {
		client.getFileManager().createRecoverProcess(file, versionSelectorListener.getFileVersionSelector()).execute();
		fail("Expected exception was not thrown.");
	} catch(ProcessExecutionException pex) {
		// expected exception since no version selected when cancelled.
		logger.info("Exception: {}", pex.getMessage());
	}

	int numElementsAfter = root.list().length;
	assertEquals(numElementsBefore, numElementsAfter);
}
 
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:19,代码来源:FileVersionSelectorTest.java


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