⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myjxta.java

📁 jxta官方例程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    setStatus(STRINGS.getString("status.dialog.listener.remove") + ": "		    + pn);	    DialogManager.getInstance(g, pn, PipeService.UnicastType)		    .clearPipeListeners(peerGroup);	    setStatus(STRINGS.getString("status.dialog.clear") + ": "		    + g.getName());	    	    List<Dialog> dialogsInGroup=DialogManager.getDialogsForGroup(g);	    if (dialogsInGroup!=null){		    for (Iterator<Dialog> p = dialogsInGroup.iterator(); p.hasNext();) {			Dialog d = p.next();			removeDialog(d);		    }	    }	    // xxx: sould the following call remove all of the above	    // pipe listeners	    DialogManager.clear(g);	    setStatus(STRINGS.getString("status.share.resign") + ": "		    + g.getName());	    // stop the share manger	    ShareManager shareManager = ShareManager.getShareManager(this, g,		    false);	    if (shareManager != null) {		shareManager.unshareAll();		shareManager.stop();	    }	    SearchManager.getInstance().destoy();	    // LOG.error(g.getName()+" - sharemanger stopped");	    // and finally resign	    try {		// xxx: shouldn't group.resign() do this		peerGroup.getMembershipService().resign();		g.resign(false);		// LOG.error(g.getName()+" - resign done");	    } catch (PeerGroupException pge) {		String msg = "Error resigning from " + g.getName() + ": "			+ pge.getMessage();		if (LOG.isEnabledFor(Level.ERROR)) {		    LOG.error(msg, pge);		}		setStatus(msg);	    }	    if (!g.isJoined()) {		// todo: clarify: we can call removeFromJoinedGroups from within                // a Object repository listener,		// but due to the fact that the repository removes all dependend                // nodes recursivly this		// will not be accurate (sub groups would also be removed, but                // they are still joined?)		removeFromJoinedGroups(g);		// xxx: hack		Group parentGroup = g.getParentGroup();		if (this.view != null && parentGroup != null) {		    this.view			    .setTitle(this.peerName + "@" + parentGroup != null ? parentGroup				    .getName()				    : "null");		}	    }	}	return !g.isJoined();    }    /**         * Add a new JxtaNode object to the displayed tree. View takes care to         * not put in nodes twice         *          * @param node         *                the node to display         */    public void addJxtaNode(JxtaNode node) {	addJxtaNode(node, false);    }    public void addJxtaNode(JxtaNode node, boolean select) {	addJxtaNode(node, select, true);    }    public void addJxtaNode(final JxtaNode node, boolean select,	    boolean p_addToTree) {	if (p_addToTree) {	    this.view.addJxtaNode(node, select);	}	JxtaNode parent = node.getParent();	if (parent == null) {	    parent = node.getJxtaNode().getParent();	}	MyJxtaObjectRepository.getObjectRepository().add(node, parent);    }    public void removeJxtaNode(JxtaNode p_jxtaNode) {	view.removeJxtaNode(p_jxtaNode);	MyJxtaObjectRepository.getObjectRepository().remove(p_jxtaNode);    }    public void addListener(DialogListener listener) {	boolean isEmpty = true;	for (Iterator<PluginPanel> p = this.view.getPluginPanels().iterator(); p		.hasNext();) {	    p.next().getDialog().addListener(listener);	    isEmpty = false;	}	if (isEmpty) {	    if (LOG.isEnabledFor(Level.WARN)) {		LOG.warn("PluginPanel Plugin Collection is empty");	    }	}    }    public void removeListener(DialogListener listener) {	for (Iterator<PluginPanel> o = this.view.getPluginPanels().iterator(); o		.hasNext();) {	    o.next().getDialog().removeListener(listener);	}    }    public void addInboundFilter(DialogFilter filter) {	for (Iterator<PluginPanel> o = this.view.getPluginPanels().iterator(); o		.hasNext();) {	    o.next().getDialog().getInboundFilters().addFilter(filter);	}    }    public void removeInboundFilter(Class dialogFilterClass) {	for (Iterator<PluginPanel> o = this.view.getPluginPanels().iterator(); o		.hasNext();) {	    o.next().getDialog().getInboundFilters().removeFilter(		    dialogFilterClass);	}    }    public void addOutboundFilter(DialogFilter filter) {	for (Iterator<PluginPanel> o = this.view.getPluginPanels().iterator(); o		.hasNext();) {	    o.next().getDialog().getOutboundFilters().addFilter(filter);	}    }    public void removeOutboundFilter(Class<? extends Object> dialogFilterClass) {	for (Iterator<PluginPanel> o = this.view.getPluginPanels().iterator(); o		.hasNext();) {	    o.next().getDialog().getOutboundFilters().removeFilter(		    dialogFilterClass);	}    }    public View getView() {	return this.view;    }    /**         * Application shutdown         */    public void destroy() {	new Thread("DestroyMyJxta Thread") {	    public synchronized void start() {		setDaemon(true);		super.start();	    }	    public void run() {		try {		    ShareManager.unpublish();		    int joinedCount = joinedGroups.size();		    for (int i = joinedCount - 1; i >= 0; i--) {			Group g = joinedGroups.get(i);			resignGroup(g);		    }		    if (joinedGroups.size() > 0) {			LOG.error("did not leave all groups cleanly!");		    }		    try {			if (m_pluginContainer != null) {			    m_pluginContainer.destroy();			}		    } catch (Exception e) {			e.printStackTrace();		    }		    if (MyJXTA.this.administrationListener != null) {			MyJXTA.this.administrationListener.interrupt();			Env.delete(new File(Env.getHomeDirPath()				+ File.separator + Env.ADMINISTRATION_PORT));		    }		    view.disposeView();		    MyPreferenceManager.getInstance().shutdown();		    administrationListener.stopListener();		    LogManager.shutdown();		} catch (Throwable e) {		    e.printStackTrace();		} finally {		    // nano: i would like to avoid this call - but CMS has a                        // bug and will never close one		    // of his MessageProcessor Threads @see                        // net.jxta.share.MessageProcessor.run(MessageProcessor.java:105)		    System.exit(0);		}	    }	}.start();    }    /**         * Starts a new timer task         *          * @param task         *                the task to start         * @param period         *                the period between execution in minutes         */    public void startTimer(TimerTask task, int period) {	long p = period * 60 * 1000;	if (timer == null) {	    timer = new Timer();	}	timer.schedule(task, p, p);    }    /**         * Changes the status information that is displayed in the ui.         *          * @param status         *                the new status information to display         */    public void setStatus(String status) {	if (status != null) {	    this.view.setStatus(status);	    Status.getInstance().statusEvent(status);	}    }    public void groupEvent(Group group, String status, @SuppressWarnings("unused")    EventObject p_re) {	if (status != null) {	    setStatus(group.getName() + ":" + status);	}	if (Group.CONNECT.equals(status)) {	    // xxx: check to see if group is discoverable	    discover(group);	}	if (group.isVisible()) { // do nothing for the invisible npg	    getPluginContainer().updateGroupState(group);	}    }    /**         * Initializes the MyJxta instance         *          * @modified 2005-06-21 jamoore.jxta.org fix for issue #286         */    private void initialize() {	configureHTTPProxy();	Group npgWrapper = null;	setStatus(STRINGS.getString("status.jxta.startNetPeerGroup"));	try {	    PeerGroup worldPeerGroup = new WorldPeerGroupFactory()		    .getInterface();	    PeerGroup netPeerGroup = new NetPeerGroupFactory(worldPeerGroup)		    .getInterface();	    npgWrapper = new Group(this, netPeerGroup, null, false);	} catch (PeerGroupException pge) {	    if (LOG.isEnabledFor(Level.ERROR)) {		LOG.error("Caught unexpected Exception", pge);	    }	}	if (npgWrapper == null) {	    setStatus(STRINGS.getString("error.jxta.start"));	    return;	}	this.peerName = npgWrapper.getPeerGroup().getPeerName();	// this.preferencesManager = new PreferenceManager(this);	this.myPreferenceManager = MyPreferenceManager.getInstance();	setStatus(STRINGS.getString("status.jxta.joiningApplicationGroup"));	String gid = Constants.getInstance().get(Constants.GROUP_ID, "").trim();	final boolean mainGroupIsNetPeerGroup = gid.length() == 0;	// the normal usecase is that we are running in a dedicated myjxta        // group... in this usecase the netpeergroup is not important for the user 	// and therefore should not be visible.	// however, if the NPG is our application group we want it to be visible	npgWrapper.setVisible(mainGroupIsNetPeerGroup);	joinGroup(npgWrapper, false, false);	initializeGroup(npgWrapper);	seedGroup(this.view.getGroup());	myPreferenceManager.init();	// this.preferencesManager.presetPreferences();    }    private void configureHTTPProxy() {	Constants c = Constants.getInstance();	URL hp = null;	try {	    hp = c.getURL(Constants.PROXY_HTTP);	} catch (ConversionException ce) {	    if (LOG.isEnabledFor(Level.DEBUG)) {		LOG.debug("unable to get proxy url: " + c.get(Constants.PROXY_HTTP));	    }	}	System.setProperty(Env.HTTP_PROXY_HOST, hp != null ? hp.getHost() : "");	System.setProperty(Env.HTTP_PROXY_PORT, hp != null ? String.valueOf(hp		.getPort()) : "");    }    private void initializeGroup(Group parent) {	initializeGroup(parent, Constants.GROUP, "/@id");    }    private void initializeGroup(Group parent, String queryPrefix,	    String queryPostfix) {	String prefix = queryPrefix != null ? queryPrefix.trim() : null;	String postfix = queryPostfix != null ? queryPostfix.trim() : null;	if (prefix != null && postfix != null) {	    Constants c = Constants.getInstance();	    for (Iterator gi = c.getAll(prefix + postfix).iterator(); gi		    .hasNext();) {		String gid = ((String) gi.next()).trim();		if (gid.length() > 0) {		    String q = prefix + "[@id=\"" + gid + "\"]";		    String gn = c.get(q + "/@name", Defaults.GROUP_NAME);		    String gp = c.get(q + "/@password", null);		    String gd = c.get(q + "/@description",			    Defaults.GROUP_DESCRIPTION);		    String gar = c.get(q + "/@autoRendezVousPeriod", String			    .valueOf(Constants.AUTO_RENDEZVOUS_JOIN_PERIOD));		    setStatus(STRINGS.getString("status.group.create") + " "			    + gn);		    Group g = createGroupObject(parent, gn, gd, gp, gid);		    if (g != null) {			joinGroupWithAutoIntervall(gar, g);			initializeGroup(g, q, "/group/@id"); // recursive                                                                // call (we can                                                                // automatically                                                                // join inner                                                                // groups)		    } else {			setStatus(STRINGS.getString("error.group.create") + " "				+ gn);		    }		}	    }	}    }    private void joinGroupWithAutoIntervall(String autoRdvIntervall, Group p_g) {	int garp = Constants.AUTO_RENDEZVOUS_JOIN_PERIOD;	try {	    garp = Integer.parseInt(autoRdvIntervall);	} catch (NumberFormatException nfe) {	    if (LOG.isDebugEnabled())		LOG.debug("invalid auto rdv: " + autoRdvIntervall);	}	p_g.setVisible(true);	p_g.setAutoRendezVousPeriod(garp);	joinGroup(p_g, true, true); // this is the point that can take quite                                        // long (authenticator is started)    }    private Group createGroupObject(Group parent, String p_gn, String p_gd,	    String p_gp, String p_gid) {	Group g = null;	try {	    PeerGroup ppg = parent.getPeerGroup();	    PeerGroupAdvertisement pga = PeerGroupUtil.create(ppg, p_gn, p_gd,		    p_gp, 0, (PeerGroupID) PeerGroupID.create(new URI(p_gid)));	    g = new Group(this, ppg.newGroup(pga), parent);	} catch (Exception e) {	    if (LOG.isEnabledFor(Level.ERROR)) {		LOG.error("Caught unexpected Exception", e);	    }	}	return g;    }    private void seedGroup(Group parent) {	String gid = System.getProperty(GROUP_ID, "").trim();	String gn = System.getProperty(GROUP_NAME, "").trim();	String gd = System.getProperty(GROUP_DESCRIPTION,		Defaults.GROUP_DESCRIPTION).trim();	String autoRdvIntervall = System.getProperty(		GROUP_AUTO_RENDEZVOUS_PERIOD,		String.valueOf(Constants.AUTO_RENDEZVOUS_JOIN_PERIOD)).trim();	String gp = null;	if (gid.length() > 0) {	    setStatus(STRINGS.getString("status.group.create") + " " + gn);	    Group g = createGroupObject(parent, gn, gd, gp, gid);	    if (g != null) {		joinGroupWithAutoIntervall(autoRdvIntervall, g);	    } else {		setStatus(STRINGS.getString("error.group.create") + " " + gn);	    }	}    }    /**         * Restore settings from previous invocation         */    private void restore(Group group) {	// xxx: restore friends, groups, shares	PeerGroup pg = group.getPeerGroup();	setStatus(STRINGS.getString("status.group.restore"));	for (Iterator g = PeerGroupUtil.getAdvs(pg, null).iterator(); g		.hasNext();) {	    GroupNode parentGroupNode = new GroupNode(group);	    GroupNode newGroupNode = new GroupNode(new Group(this,		    (PeerGroupAdvertisement) g.next(), group));	    newGroupNode.setParent(parentGroupNode);	    addJxtaNode(newGroupNode);	}	setStatus(STRINGS.getString("status.peer.restore"));	// String term = Dialog.IMFREE_USER_NAME + Dialog.IMFREE_DELIMITER +	// SearchModifier.WILDCARD;	String term = OneToOneCommandDialog.IMFREE_COMMAND_NAME		+ Dialog.IMFREE_DELIMITER + SearchModifier.WILDCARD;	for (Iterator p = PipeUtil.getAdvs(pg, term).iterator(); p.hasNext();) {	    PeerNode node = new PeerNode(		    new Peer((PipeAdvertisement) p.next()), group);	    node.setParent(new GroupNode(group));	    addJxtaNode(node);	}    }    private void discover(Group group) {	// if (SearchManager.getInstance().search(Searcher.GROUP, group, this))        // {	// setStatus(STRINGS.getString("status.group.discover"));	// }	if (SearchManager.getInstance().search(Searcher.PIPE, group, this)) {	    setStatus(STRINGS.getString("status.peer.discover"));	}    }    public PluginContainer getPluginContainer() {	return m_pluginContainer;    }    public ArrayList<String> getAdministrationBuffer() {	if (administrationBuffer == null)	    administrationBuffer = new ArrayList<String>();	return administrationBuffer;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -