📄 cms.java
字号:
} /** * @param sl the SearchListener object to remove. * @see SearchListener * @see #addSearchListener(SearchListener) */ public void removeSearchListener(SearchListener sl) { if(listQueue != null) listQueue.removeSearchListener(sl); } /** * Returns the EndpointService for this service. * * @return EndpointService EndpointService for this service. * */ public EndpointService getEndpointService() { return group.getEndpointService(); } /** * Returns the Content Manager for this service. * * @return ContentManager the Content Manager. * */ public ContentManager getContentManager() { return contentManager; } /** * Returns the endpoint address for this service. * * @return String the endpoint address. * */ public String getEndpointAddress() { return "jxta://" + getPeerId(group) + "/" + serviceName + "/" + getGroupId(group); } public void processIncomingMessage(Message message, EndpointAddress srcAddr, EndpointAddress dstAddr) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("processing an Incoming Message"); } if (message != null) { // Handle the message try { String messageType = popString(message, MESSAGE_TYPE); if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("handleMessage type = " + messageType); } if (LIST_REQUEST.equals(messageType)) { // queue up on the list command queue listQueue.push(message); } else if (GET_REQUEST.equals(messageType)) { // queue up on the get command queue getQueue.push(message); } } catch (IOException e) {} } } /** * Process the resolver query, and generate response * @return GenericResolverMsg Response to the query * @param query ResolverQueryMsg query * * @exception NoResponseException is thrown when the resolver service * does not have an response and is not interested by the response. * @exception ResendQueryException is thrown when the resolver service * does not have a response, but is interested by the response. In that * case, the resolver service is responsible for forward the response * to the original peer that has issued the query. * @exception DiscardQueryException is thrown when the resolver service * has decided that the query should simply be ignored. * @exception IOException is thrown when the service resolver was not able to * process the query * */ public int processQuery(ResolverQueryMsg query) { String queryStr = query.getQuery(); if (LOG.isEnabledFor(Level.DEBUG)) LOG.debug("received query: "+queryStr); int index = queryStr.indexOf(';'); String addressStr = queryStr.substring(0, index); String subString = queryStr.substring(index+1+"substring=".length()); if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("addressStr = "+addressStr); LOG.debug("substring = "+subString); } //should it have a namespace? Message message = new Message(); message.addMessageElement( new ByteArrayMessageElement(CMS.REQUEST_ID,encodeAs ,new String("none").getBytes(),null)); message.addMessageElement( new ByteArrayMessageElement(CMS.RETURN_ADDRESS, encodeAs ,addressStr.getBytes(),null)); if (null != subString) { message.addMessageElement( new ByteArrayMessageElement(CMS.QUERY_SUBSTRING, encodeAs ,subString.getBytes(),null)); } // queue up on the list command queue listQueue.push(message); return ResolverService.Repropagate; } /** * call back method, when messages are received by the ResolverService * it calls back this method to deal with received responses * @param response ResolverQueryMsg reponse * */ public void processResponse(ResolverResponseMsg response) { if (LOG.isEnabledFor(Level.DEBUG)) LOG.debug("received response: "+response.getResponse()); } /** * Returns the String contained in the given tag in the given Message. * * @return String from given tag in given message. * */ public static String popString(Message message, String tag) throws IOException { MessageElement substrQueryEl = message.getMessageElement(tag); if(substrQueryEl == null) { if(LOG.isInfoEnabled()) LOG.info("message is missing a \"" + tag + "\" element."); return ""; } return substrQueryEl.toString(); } /** * Returns the String version of the groupId for the given group. * * @return String groupId for the given group * */ public static String getGroupId(PeerGroup group) { // XXX 20011105 bondolo@jxta.org why not just use the urn value? return group.getPeerGroupID().getUniqueValue().toString(); } /** * Returns the String version of the groupId for the given group. * * @return String peerId for the given group * */ public static String getPeerId(PeerGroup group) { // XXX 20011105 bondolo@jxta.org why not just use the urn value? return group.getPeerID().getUniqueValue().toString(); } /** * Returns a ContentAdvertisement create from the given stream * * @return ContentAdvertisement the created ContentAdvertisement * */ public static ContentAdvertisement createContentAdvertisement(InputStream is) throws IOException { return new ContentAdvertisementImpl(is); } /** * Publish into Discovery the ContentAdvertisement of the ContentManager. **/ private void publishAllContents () { DiscoveryService disco = (DiscoveryService) group.getDiscoveryService(); Content[] contents = null; if (contentManager == null) { // Nothing to share. return; } contents = contentManager.getContent(); if ((contents == null) || (contents.length == 0)) { // Nothing to share. return; } for (int i = 0; i < contents.length; ++i) { try { Content content = contents [i]; publishContent (content); } catch (Exception ez) { System.err.println ("Can't publish advertisement: " + ez); continue; } } } /** * Publish into Discovery the ContentAdvertisement of the ContentManager. **/ protected void publishContent (Content content) { if (content == null) { // No content. Nothing to do return; } DiscoveryService disco = (DiscoveryService) group.getDiscoveryService(); try { ContentAdvertisement adv = content.getContentAdvertisement(); adv.setAddress (getEndpointAddress()); disco.publish (adv, DEFAULT_LOCAL_ADV_LIFETIME, DEFAULT_REMOTE_ADV_LIFETIME); } catch (Exception ez) { System.err.println ("Can't publish advertisement: " + ez); return; } } protected void forgetContent (Content content) { // FIXME 11/03/2002 lomax@jxta.org TBD } public void finalize () { stopApp(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -