?? workspaceconnection.java
字號:
package connex.core.net;
import java.net.URISyntaxException;
import java.io.IOException;
import net.jxta.id.ID;
import java.net.URI;
import net.jxta.document.AdvertisementFactory;
import net.jxta.id.IDFactory;
import net.jxta.pipe.InputPipe;
import net.jxta.protocol.PipeAdvertisement;
import net.jxta.pipe.OutputPipe;
import connex.core.WS.*;
import net.jxta.peergroup.*;
import net.jxta.pipe.PipeMsgListener;
import net.jxta.endpoint.Message;
import net.jxta.pipe.PipeMsgEvent;
import java.util.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author Hisham Khalil
* @version 1.0
*/
public class WorkspaceConnection extends Connection implements PipeMsgListener {
private InputPipe inputPipe = null;
private OutputPipe outputPipe = null;
private InputPipe privinputPipe = null;
private OutputPipe privOutputPipe = null;
/**
* @directed
* @link aggregationByValue
*/
private PipePair pipes = null;
private Hashtable<String,
OutputPipe> outPipeCash = new Hashtable<String, OutputPipe>();
/**
*
* @param pg PeerGroup
* @param listener ConnectionClient
*/
public WorkspaceConnection(PeerGroup pg, ConnectionClient listener) {
super(pg, listener);
}
/**
*
*/
public boolean connect() {
pipes = PipeUtils.createWorkspacePipe(pg, listener.getClientName(), this);
if (this.inputPipe == null) {
this.inputPipe = pipes.getInputPipe();
}
if (this.outputPipe == null) {
this.outputPipe = pipes.getOutputPipe();
}
return (inputPipe != null && outputPipe != null) ? true : false;
}
public boolean disConnect() {
if (outputPipe != null) {
outputPipe.close();
outputPipe = null;
}
if (inputPipe != null) {
inputPipe.close();
inputPipe = null;
}
listener = null;
Enumeration num = outPipeCash.elements();
OutputPipe op;
while (num.hasMoreElements()) {
op = (OutputPipe) num.nextElement();
op.close();
outPipeCash.remove(op);
}
return true;
}
/**
*
* @param msg Message
*/
public synchronized void send(Message msg) {
try {
outputPipe.send(msg);
sent++;
} catch (IOException ex) {
ex.printStackTrace();
}
}
/**
* Creates a private pipe additional to the WorkspacePipe and return the pipeID as String
* @return String
*/
public String getMyBackDoorID() {
if (privinputPipe == null) {
this.privinputPipe = PipeUtils.createInputPipe(this);
}
System.out.println(privinputPipe.getType() + " created for "+this.getOwner());
return privinputPipe.getPipeID().toString();
}
public synchronized void sendToBackDoor(String backID, Message msg) {
privOutputPipe = outPipeCash.get(backID);
if (privOutputPipe == null) {
privOutputPipe = PipeUtils.createOutputPipe(backID);
if (privOutputPipe != null) {
outPipeCash.put(backID, privOutputPipe);
}
}
try {
privOutputPipe.send(msg);
sent++;
} catch (Exception ex) {
}
}
/**
* Called for each pipe message event that occurs.
*
* @param event The event being received.
*/
public synchronized void pipeMsgEvent(PipeMsgEvent event) {
Message msg = event.getMessage();
listener.reciveMessage(msg);
recived++;
return;
}
public ConnectionClient getOwner() {
return listener;
}
public synchronized long getSentMessageCount() {
return sent;
}
public synchronized long getRecivedMessageCount() {
return recived;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -