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


Java Number160类代码示例

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


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

示例1: xPut

import net.tomp2p.peers.Number160; //导入依赖的package包/类
private void xPut(Entry entry) throws IOException {
    FutureGet fg = peer.get(entry.getID()).getLatest().start()
            .awaitUninterruptibly();
    Pair<Number640, Data> pair = checkVersions(fg.rawData());
    Data newData = new Data(entry);
    Number160 v = pair.element0().versionKey();
    long version = v.timestamp() + 1;
    newData.addBasedOn(v);
    Pair<Number160, Data> pair3 = new Pair<Number160, Data>(new Number160(version,
            newData.hash()), newData);
    FuturePut fp1 = peer.put(entry.getID()).data(Number160.ZERO, pair3.element1().prepareFlag(), pair3.element0()).start().awaitUninterruptibly();
    Pair<Number640, Byte> pair2 = checkVersions(fp1.rawResult());
    FuturePut fp = peer.put(entry.getID())
            .versionKey(pair2.element0().versionKey()).putConfirm()
            .data(new Data()).start().awaitUninterruptibly();
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:17,代码来源:FSModifyHelper.java

示例2: getAndUpdate

import net.tomp2p.peers.Number160; //导入依赖的package包/类
private Pair<Number160, Data> getAndUpdate(Directory parentDir, Entry child) throws InterruptedException, ClassNotFoundException,
        IOException {
    Random RND = new Random(42L);
    Pair<Number640, Data> pair = tryToGet(parentDir.getID());
    // we got the latest data
    if (pair != null) {
        // update operation is append
        parentDir.addChild(child.getEntryName(), child.getID(), child.getType());
        Data newData = new Data(parentDir);
        Number160 v = pair.element0().versionKey();
        long version = v.timestamp() + 1;
        newData.addBasedOn(v);
        //since we create a new version, we can access old versions as well
        return new Pair<Number160, Data>(new Number160(version,
                newData.hash()), newData);
    }
    return null;
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:19,代码来源:FSModifyHelper.java

示例3: getAndUpdate_remove

import net.tomp2p.peers.Number160; //导入依赖的package包/类
private Pair<Number160, Data> getAndUpdate_remove(Directory parentDir, Entry child) throws InterruptedException, ClassNotFoundException,
        IOException {
    Random RND = new Random(42L);
    Pair<Number640, Data> pair = tryToGet(parentDir.getID());
    // we got the latest data
    if (pair != null) {
    // update operation is append
        parentDir.removeChild(child.getEntryName());
        Data newData = new Data(parentDir);
        Number160 v = pair.element0().versionKey();
        long version = v.timestamp() + 1;
        newData.addBasedOn(v);
    //since we create a new version, we can access old versions as well
        return new Pair<Number160, Data>(new Number160(version,
                newData.hash()), newData);
    }
    return null;
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:19,代码来源:FSModifyHelper.java

示例4: tryToGet

import net.tomp2p.peers.Number160; //导入依赖的package包/类
private Pair<Number640, Data> tryToGet(Number160 key) {
    Pair<Number640, Data> pair = null;
    for (int i = 0; i < 5; i++) {
        FutureGet fg = peer.get(key).getLatest().start()
                .awaitUninterruptibly();
        // check if all the peers agree on the same latest version, if not
        // wait a little and try again
        pair = checkVersions(fg.rawData());
        if (pair != null) {
            break;
        }
        // something went wrong, have to wait
        try {
            Thread.sleep(RND.nextInt(500));
        } catch (InterruptedException e) {
            //TODO find out what is it
            e.printStackTrace();
        }
    }
    return pair;
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:22,代码来源:FSModifyHelper.java

示例5: createDir

import net.tomp2p.peers.Number160; //导入依赖的package包/类
@Override
public void createDir(String path) throws ClassNotFoundException, FsException, IOException {
    Path subPaths = Paths.get(path);
    int pathLength = subPaths.getNameCount();
    if (pathLength == 0) {
        throw new NotADirectoryException("Don't create a root node like that! Path: "+path);
    }
    Directory parentEntry = getDirectory(subPaths.getParent().toString());

    if (parentEntry.getChild(subPaths.getFileName().toString()) != null) {
        throw new FileExistsException(path);
    }

    Number160 newKey = Number160.createHash(UUID.randomUUID().hashCode());
    Directory newDir = new Directory(newKey, subPaths.getFileName().toString());

    helper.addNewEntry(parentEntry, newDir);
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:19,代码来源:TreeController.java

示例6: createFile

import net.tomp2p.peers.Number160; //导入依赖的package包/类
@Override
public void createFile(String path) throws ClassNotFoundException, FsException, IOException {

    Path subPaths = Paths.get(path);

    int pathLength = subPaths.getNameCount();
    if (pathLength == 0) {
        throw new NoSuchFileOrDirectoryException("Can not create such file");
    }

    Directory parentEntry = getDirectory(subPaths.getParent().toString());
    if (parentEntry.getChild(subPaths.getFileName().toString()) != null) {
        throw new FileExistsException(path);
    }


    Number160 newKey = Number160.createHash(UUID.randomUUID().hashCode());
    File newFile = new File (newKey, subPaths.getFileName().toString());

    //this is new locking logic, due to fuse constraints we have to associate a file creation with the respective owner
    newFile.setDirtyBit(true);
    newFile.setModifierPeer(peer.peerID());


    helper.addNewEntry(parentEntry, newFile);
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:27,代码来源:TreeController.java

示例7: createAndAttachPeersDHT

import net.tomp2p.peers.Number160; //导入依赖的package包/类
public static PeerDHT[] createAndAttachPeersDHT(int nr, int port) throws IOException {
    
	Random random = new Random();
	
	PeerDHT[] peers = new PeerDHT[nr];
    for (int i = 0; i < nr; i++) {
        if (i == 0) {
            peers[0] = new PeerBuilderDHT(new PeerBuilder(new Number160(random)).ports(port).start()).start();

        } else {
            peers[i] = new PeerBuilderDHT(new PeerBuilder(new Number160(random)).masterPeer(peers[0].peer()).start()).start();

        }
    }
    return peers;
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:17,代码来源:FileContentControllerTest.java

示例8: setup

import net.tomp2p.peers.Number160; //导入依赖的package包/类
@Before
public void setup() {
    //setup logging to console
    //org.apache.log4j.BasicConfigurator.configure();


    try {
        //initialize network
        peers = createAndAttachPeersDHT(nr, port);
        bootstrap(peers);

        //initialize controller with a peer
        controller = new TreeController(peers[local]);


        //create a root node
        Directory rootDir = new Directory(Number160.ZERO, rootName);
        //upload root into DHT
        Data data = new Data(rootDir);
        FutureDHT futureDHT = peers[3].put(Number160.ZERO).data(data).start();
        futureDHT.awaitUninterruptibly();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:27,代码来源:TreeControllerTest.java

示例9: testRenameEntry

import net.tomp2p.peers.Number160; //导入依赖的package包/类
@Test
public void testRenameEntry() throws ClassNotFoundException, FsException, IOException {
    String oldName = "/entryToRename";
    String newName = "/newName";

    controller.createDir(oldName);

    Number160 entryID = controller.resolvePath(oldName).getID();

    controller.renameEntry(oldName, newName);

    //assert that the entry has the new name
    assertEquals(newName, "/" + getEntryFromID(entryID).getEntryName());

    //assert that the parent also stores the new name
    assertTrue(controller.readDir("/").contains("newName"));
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:18,代码来源:TreeControllerTest.java

示例10: initDHT

import net.tomp2p.peers.Number160; //导入依赖的package包/类
public DHTManager initDHT() throws IOException
{
	Random rand = new Random();
	Bindings bind = new Bindings();
	bind.addInterface(Config.getInstance().getNetworkInterface());
	peer = new PeerBuilderDHT(new PeerBuilder(new Number160(rand)).ports(Config.getInstance().getPortDHT()).start()).start();
	
	this.connectToConnectNode();
	/*new IndirectReplication(peer).start();
	
	InetAddress address = Inet4Address.getByName(Config.getInstance().getConnectNode());
	FutureDiscover futureDiscover = peer.peer().discover().inetAddress(address).ports(Config.getInstance().getPortDHT()).start();
	futureDiscover.awaitUninterruptibly();
	FutureBootstrap futureBootstrap = peer.peer().bootstrap().inetAddress(address).ports(Config.getInstance().getPortDHT()).start();
	futureBootstrap.awaitUninterruptibly();*/
	
	return this;
}
 
开发者ID:reTHINK-project,项目名称:dev-registry-global,代码行数:19,代码来源:DHTManager.java

示例11: get

import net.tomp2p.peers.Number160; //导入依赖的package包/类
/**
 * Retrieves the social record from the DHT.
 *
 * @param key
 * @return the social record
 * @throws ClassNotFoundException
 * @throws IOException
 * @throws GUIDNotFoundException 
 */
public String get(String key) throws GUIDNotFoundException
{
	try
	{
		FutureGet futureGet = peer.get(Number160.createHash(key)).start();
		futureGet.awaitUninterruptibly();
		
		// TODO: use non-blocking?
		if(futureGet.isSuccess() && futureGet.data() != null)
		{
			return futureGet.data().object().toString();
		}
		else
		{
			throw new GUIDNotFoundException("GUID not found");
		}
		
		//return null; // TODO: decide on sentinel value
	}
	catch(ClassNotFoundException | IOException e)
	{
		throw new GUIDNotFoundException("GUID not found");
	}
}
 
开发者ID:reTHINK-project,项目名称:dev-registry-global,代码行数:34,代码来源:DHTManager.java

示例12: updateOverlay

import net.tomp2p.peers.Number160; //导入依赖的package包/类
public void updateOverlay(PeerDHT peer)	throws OverlayException {
	log.info("Updating UNaDa information inside DHT.");
	updateUnadaInfo(peer);
	manager.resolveGeoLocation(uNaDaInfo);
	FutureRemove remove = peer.remove(Number160.createHash(uNaDaInfo.getUnadaID())).all().start();
	try {
		remove.await();
	} catch (InterruptedException e1) {
		log.error("Failed to delete old contents.", e1);
	}
	
	FuturePut futurePut;
	
	try {
		
		log.debug("Updating Unada with address: {}, tcp port {}, udp port {}.", uNaDaInfo.getUnadaAddress(), uNaDaInfo.getTcpPort(), uNaDaInfo.getUdpPort());
		futurePut = peer.put(Number160.createHash(uNaDaInfo.getUnadaID())).data(new Data(uNaDaInfo).ttlSeconds(UNADA_INFO_TTLs + 30)).start();
		futurePut.awaitUninterruptibly();
		if(!futurePut.isSuccess()){
			throw new OverlayException("Put for UNaDa info failed.");
		}
	} catch (IOException e) {
		throw new OverlayException("Unexpected Exception:", e);
	}
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:26,代码来源:Overlay.java

示例13: advertiseContent

import net.tomp2p.peers.Number160; //导入依赖的package包/类
public void advertiseContent(long... contentID) {
	log.info("Advertising contents into DHT: ", contentID);
	deleteContents(contentID);
	for(long id : contentID){
		try {
			FuturePut put = peer.put(Number160.createHash(id)).data(Number160.createHash(uNaDaInfo.getUnadaID()), new Data(uNaDaInfo).ttlSeconds(UNADA_INFO_TTLs + 30)).start();
			put.awaitUninterruptibly();
			if(put.isSuccess()){
				log.debug("{} - Successfully advertised conten {} to DHT.",uNaDaInfo.getUnadaID() , id);
			}else{
				log.warn("{} - Failed to advertised conten {} to DHT.", uNaDaInfo.getUnadaID(), id);
			}
		} catch (IOException e) {
			log.error("{} - Failed while advertising conten {}.", uNaDaInfo.getUnadaID(), contentID, e);
		}
		manager.queryProviders(id, null);
	}
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:19,代码来源:Overlay.java

示例14: resultUploaded

import net.tomp2p.peers.Number160; //导入依赖的package包/类
/**
     * Called when the job owner has been notified that a certain result has been uploaded.
     * @param replicaID ID of the replica who's result was uploaded
     */
    private void resultUploaded(final ReplicaID replicaID){
        System.out.println("Replica was completed: "+replicaID);

        final Number160 resultKey = replicaManager.getReplicaResultKey(replicaID);
//        System.out.println("\tResultKey: "+resultKey);

        client.addListener(new OperationFinishedListener(client, resultKey, CommandWord.GET) {
            @Override
            protected void operationFinished(Operation operation) {
                if (operation.isSuccess()) {
//                    System.out.println("RESULT RAW: "+operation.getResult().toString());
                    Data resultData = (Data) operation.getResult();

                    byte[] resultArray = resultData.getData();
                    System.out.println("Result downloaded successfully, \n\tresult holds "+resultArray.length+" bytes.");
                    replicaManager.replicaFinished(replicaID, resultArray);
                } else {
                    System.out.println("DownloadOperation failed! " + operation.getErrorCode()
                            + "\n\t" + operation.getReason());
                }
            }
        });
        client.get(resultKey, client.getID());

    }
 
开发者ID:GDCN,项目名称:GDCN,代码行数:30,代码来源:TaskPasser.java

示例15: issueRequest

import net.tomp2p.peers.Number160; //导入依赖的package包/类
public void issueRequest(final Request r) throws IOException {
	String[] temp = { "" + r.getId(), r.getFingerprint() };
	FutureDHT fdht = p.send(new Number160(new Random())).setObject(temp)
			.start();

	fdht.addListener(new BaseFutureAdapter<FutureDHT>() {

		@Override
		public void operationComplete(FutureDHT f) throws Exception {
			if (f.isFailed()) {
				Logger.getLogger(PeerManager.class.getName()).log(
						Level.WARN,
						"Request " + r.getId() + "from User " + r.getUser().getName()
								+ " failed.");
			} else {
				Logger.getLogger(PeerManager.class.getName()).log(
						Level.INFO,
						"Request " + r.getId() + r.getId() + "from User "
								+ r.getUser().getName() + " successfully issued.");
			}

		}

	});
}
 
开发者ID:SH4DY,项目名称:swazam,代码行数:26,代码来源:PeerManager.java


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