📄 whiteboardservice.java
字号:
package connex.plugins.whiteboard;
import connex.core.net.WorkspaceConnection;
import connex.session.plugin.Plugin;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import connex.core.net.ConnectionFactory;
import connex.core.net.ConnectionClient;
import net.jxta.endpoint.Message;
import connex.core.net.WorkspaceConnection;
import java.io.IOException;
import org.apache.log4j.Level;
import connex.core.net.WorkspaceConnection;
import connex.core.WS.Workspace;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class WhiteboardService
implements Plugin, ConnectionClient {
private final static Logger LOG = org.apache.log4j.Logger.getLogger(
WhiteboardService.class.getName());
private static WhiteboardService instance = null;
/**
* @directed
* @link aggregationByValue
*/
private MainUI gui;
private Workspace ws = null;
/**
* @link aggregationByValue
* @directed
*/
private MessageQueue messageQ;
private boolean started = false;
private WorkspaceConnection sess;
public static int maxRetry = 3;
private int retry = 1;
/**
* @directed
* @link aggregationByValue
*/
private MessageProcessor processor;
public WhiteboardService() {
instance = this;
}
public void initPlugin(Object param) {
this.ws = (Workspace) param;
LOG.setLevel(Level.INFO);
gui = new MainUI();
sess = (WorkspaceConnection) ConnectionFactory.newWorkspaceConnection(ws, this);
}
public void startPlugin() {
if (!started) {
try {
connect();
processor = new MessageProcessor(sess);
messageQ = new MessageQueue(processor);
messageQ.start();
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info(" whitboard started");
}
}
catch (IOException ex) {
}
}
else {
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info(" PresenceService already started");
}
}
}
protected void connect() throws IOException {
if (sess.connect()) {
started = true;
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info(" PresenceService started successfully");
}
}
else {
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info(" whitboardService can't connect.. ");
}
if (retry <= maxRetry) {
LOG.info(" retry to connect whitboardService;" + retry + " .. ");
sess.disConnect();
try {
Thread.currentThread().sleep(2000);
}
catch (InterruptedException ex) {
}
connect();
retry++;
}
else {
throw new IOException("whitboardService can't connect...");
}
}
}
public JPanel getMainUI() {
return gui;
}
public void stopPlugin() {
if (started) {
sess.disConnect();
messageQ.stopIt();
gui.clear();
gui = null;
started = false;
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info(" whitboardService stoped ");
}
}
}
public void createSession(String id) {
}
public String getClientName() {
return "WhiteboardService";
}
public void reciveMessage(Message msg) {
messageQ.push(msg);
}
public void closedFromRemote() {
}
public static WhiteboardService getInstance() {
if (instance == null) {
instance = new WhiteboardService();
}
return instance;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -