📄 abstractdialog.java
字号:
public void clear() { clearListeners(); clearCache(); } /** * Remove all {@link DialogListener} objects from the {@link List} being maintained for this session. */ public void clearListeners() { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Begin clearListeners()"); } if (this.listeners != null) { this.listeners.clear(); this.listeners = null; } if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("End clearListeners()"); } } public void clearCache() { Cache.getCache(getGroup()).clear(); } /** * Dispatch a Message object to the intended receivers * * @param msg the Message object to send across an open pipe * @return true if the message was successfully dispatched, and false otherwise. */ public abstract boolean dispatch(Message msg); /** * { @inheritDoc } */ public void close(){ m_closed=true; } public abstract PluginPanel getDialogPanel(View p_myJXTAView); //quick hack --> this DialogClass is "hot" (not a template) public void activate() { } /** * @return The number of retrys the dialog will attempt when dispatching on * it's pipe. */ public int getDispatchRetryMetric() { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("In getDispatchRetryMetric()"); } return dispatchRetryMetric; } /** * Sets the number of retrys attempted to dispatch on the current pipe. * Normally the only reason a dispatch would return false is due to a * null time. Usually after a timeout on connection or remote peer has * gone down. We need a way of notifying the local peer of such a case. * As is, dispatch simply will not send a message after a number of retrys. * This megates the purpose of reliable pipes. Notification of servere errors * to child classes would be enough... * * @param dispatchRetryMetric TODO describe this param */ public void setDispatchRetryMetric(int dispatchRetryMetric) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Begin setDispatchRetryMetric(int)"); } if (dispatchRetryMetric < MIN_DISPATCH_RETRY_METRIC) { this.dispatchRetryMetric = MIN_DISPATCH_RETRY_METRIC; } else if (dispatchRetryMetric > MAX_DISPATCH_RETRY_METRIC) { this.dispatchRetryMetric = MAX_DISPATCH_RETRY_METRIC; } else { this.dispatchRetryMetric = dispatchRetryMetric; } if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("End setDispatchRetryMetric(int)"); } } /** * Send the indicated message to the intended receivers * * @param msg the message to send */ public void dispatch(String msg) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Begin dispatch(String)"); } DialogMessage dm = (DialogMessage) this.dialogMessage.clone(); dm.setMessage(msg); dispatch(dm); if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("End dispatch(String)"); } } /** * Send a DialogMessage object to its intended receivers. * DialogMessage object with an empty message will not be send * * @param msg the DialogMessage object to send */ public void dispatch(DialogMessage msg) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Begin dispatch(DialogMessage)"); LOG.debug("msg = " + msg); } if (msg != null) { DialogMessageWrapper w = new DialogMessageWrapper(this, msg); DialogFilter df = null; for (Iterator f = this.outbound != null ? this.outbound.getFilters().iterator() : Collections.EMPTY_LIST.iterator(); f.hasNext();) { df = (DialogFilter) f.next(); try { w = (DialogMessageWrapper) df.filter(w); } catch (Exception e){ e.printStackTrace(); } } if (w != null && w.isValid()) { Message m = w.toMessage(this.dialogMessage); Message messageForPostProcessing = m; /** this avoids an infinite loop on dispatch if the pipe is null */ for (int metric = getDispatchRetryMetric(); metric > 0; metric --) { if (dispatch(m)) { break; } } // do any task necessary to do after the message was send postDispatch(messageForPostProcessing); } } if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("End dispatch(DialogMessage)"); } } /** * Called if a new DialogMessage object was received. * This method informs all registered DialogListener objects * that a new DialogMessage object was received. * * @param msg the DialogMessage object that was received */ public void receive(DialogMessage msg) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Begin receive(DialogMessage)"); LOG.debug("msg = " + msg); } if (LOG.isEnabledFor(Level.INFO)) { String msgText = Text.deleteBlankLines(Text.replace(msg.getMessage(), Text.MARKUP, Text.EMPTY)); if (msgText == null || msgText.trim().length() > 0) { LOG.info(msg.getOriginator() + ": " + msgText); } } if (msg != null) { DialogMessageWrapper w = new DialogMessageWrapper(this, msg); DialogFilter df = null; // Apply each inbound filter to the message. for (Iterator f = this.inbound != null ? this.inbound.getFilters().iterator() : Collections.EMPTY_LIST.iterator(); f.hasNext();) { df = (DialogFilter) f.next(); w = (DialogMessageWrapper) df.filter(w); } // Apply each Listener to the message. // xxx: consider threading each invocation if (w != null && w.isValid() && this.listeners!=null) { synchronized (listeners) { Iterator<DialogListener> l = this.listeners.iterator(); while(l.hasNext()) { try { l.next().receive(w); } catch (Exception e){ e.printStackTrace(); } } } } } if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("End receive(DialogMessage)"); } } /** * Return whether this Dialog object is connected to a pipe * * @return true if we are connected to a pipe, false otherwise */ public boolean isConnected() { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("In isConnected()"); } return this.isConnected; } /** * Get the DialogMessage object that is used as a template * for all DialogMessage objects send via this Dialog object * * @return the DialogMessage object that is used as a template */ public DialogMessage getDialogMessage() { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("In getDialogMessage()"); } return this.dialogMessage; } /** * Perform any task that need to be performed after the * Message object was send * * @param msg the Message object that was send */ protected abstract void postDispatch(Message msg); /** * Perform any tasks that need to be performed before all * registered DialogListeners are informed that a new DialogMessage * object was received * * @param dm the DialogMessage object that was received * @return the changed DialogMessage image is any */ protected abstract DialogMessage preReceive(DialogMessage dm); /** * Change the connection status of this Dialog object * * @param isConnected to new connection status */ protected void setIsConnected(boolean isConnected) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("In isConnected(boolean)"); } this.isConnected = isConnected; } /** * Called if a new Message object was received. * The Message object is first converted to a DialogMessage * object. Then we call {@link #preReceive( DialogMessage) preReceive} * to perform any necessary pre-processing. After that all registered * DialogListener objects are informed that a new message was received * * @param msg the newly received Message object */ protected void receive(Message msg) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Begin receive(Message)"); LOG.debug("msg = " + msg); } DialogMessage dm = new DialogMessage(msg, this.dialogMessage.getKeys()); receive(preReceive(dm)); if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("End receive(Message)"); } } /** * Get a string representation of the indicated Advertisment object * * @param adv the Advertisment object for which to build the * string representation * @return a string representation of the indicated Advertisment object */ protected String advertisementToString(Advertisement adv) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Begin advertisementToString(Advertisement)"); } StringWriter sw = new StringWriter(); try { StructuredTextDocument d = (StructuredTextDocument) adv.getDocument(MimeMediaType.XMLUTF8); d.sendToWriter(sw); } catch (IOException ioe) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error("Caught unexpected Exception", ioe); } } if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("End advertisementToString(Advertisement)"); } return (sw != null ? sw.toString() : null); } /** * Set the template from which all DialogMessage objects * created by this Dialog object are build * * @param dm the new template */ protected void setDialogMessage(DialogMessage dm) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("In setDialogMessage(DialogMessage)"); } this.dialogMessage = dm; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -