?? jxtasearch.java
字號(hào):
import java.util.Enumeration;
import net.jxta.pipe.OutputPipe;
import net.jxta.pipe.OutputPipeListener;
import net.jxta.pipe.PipeService;
import net.jxta.pipe.OutputPipeEvent;
import net.jxta.protocol.PipeAdvertisement;
import net.jxta.peergroup.PeerGroup;
import net.jxta.discovery.DiscoveryService;
public class JXTASearch implements OutputPipeListener
{
private PeerGroup peerGroup;
private OutputPipe outputPipe;
public JXTASearch ( PeerGroup peerGroup ) {
this.peerGroup = peerGroup;
}//endConstructor
public PipeAdvertisement getPipeAdvertisement ( String targetPipeName ) {
Enumeration enum = null;
PipeAdvertisement pipeAdvert = null;
DiscoveryService discoveryService = peerGroup.getDiscoveryService ();
try
{
while( true ){
discoveryService.getRemoteAdvertisements (
null,
DiscoveryService.ADV,
"Name",
targetPipeName,
5
);
enum = discoveryService.getLocalAdvertisements (
DiscoveryService.ADV,
"Name",
targetPipeName
);
int i = 0;
if ( enum != null)
{
while (enum.hasMoreElements())
{
i++;
pipeAdvert = ( PipeAdvertisement ) enum.nextElement ();
}
}//if(enum != null)
if ( pipeAdvert != null )
{
System.out.println ( "JXTASearch: ["+i+"] Target (" + targetPipeName + ") found" );
break;
}//if (pipeAdvert != null)
}//while( true )
}
catch ( Exception e )
{
e.printStackTrace();
}
return pipeAdvert;
}//getPipeAdvertisement()
public void outputPipeEvent ( OutputPipeEvent e ) {
outputPipe = e.getOutputPipe ();
}//outputPipeEvent()
public OutputPipe getOutputPipe (PipeAdvertisement pipeAdvert){
try
{
PipeService pipeSvc = peerGroup.getPipeService ();
pipeSvc.createOutputPipe ( pipeAdvert, this );
while ( true )
{
if ( outputPipe != null )
break;
}//while (true)
return outputPipe;
}//try
catch ( Exception e )
{
e.printStackTrace();
}//catch
return null;
}//getOutputPipe()
}//end JXTASearch class
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -