📄 msginfo.java
字号:
this.compressed = compressed; } /** * Use for methods get, subscribe, unSubscribe, erase * * @exception IllegalArgumentException * if invoked multiple times */ public final void addKeyAndQos(String key, String qos) throws XmlBlasterException { if (!msgVec.isEmpty()) throw new IllegalArgumentException(ME + ".addKeyAndQos() may only be invoked once"); MsgUnitRaw msg = new MsgUnitRaw(key, (byte[]) null, qos); msgVec.add(msg); } /** * Use for exception message <br /> * NOTE: Exceptions don't return * * @exception IllegalArgumentException * if invoked multiple times */ public final void addException(XmlBlasterException e) throws XmlBlasterException { if (!msgVec.isEmpty()) throw new IllegalArgumentException(ME + ".addException() may only be invoked once"); MsgUnitRaw msg = new MsgUnitRaw(e.getMessage(), e.toByteArr(), e .getErrorCodeStr()); msgVec.add(msg); } /** * Use for methods update, publish. <br /> * Use for return value of method get. <br /> * Multiple adds are OK */ public final void addMessage(MsgUnitRaw msg) { msgVec.add(msg); } public final void removeMessage(MsgUnitRaw msg) { msgVec.remove(msg); } /** * Use for methods update, publish. <br /> * Use for return value of method get. <br /> * Multiple adds are OK */ public final void addMessage(MsgUnitRaw[] arr) { for (int ii = 0; ii < arr.length; ii++) msgVec.add(arr[ii]); } /** * Add a QoS value, use for methods connect, disconnect, ping. <br /> * Use for return value of methods connect, disconnect, ping, update, * publish, subscribe, unSubscribe and erase * * @exception IllegalArgumentException * if invoked multiple times */ public final void addMessage(String qos) throws XmlBlasterException { if (!msgVec.isEmpty()) throw new IllegalArgumentException(ME + ".addQos() may only be invoked once"); MsgUnitRaw msg = new MsgUnitRaw(null, (byte[]) null, qos); msgVec.add(msg); } /** * Add a QoS array value. <br /> * Use for return value of methods publishArr and erase * * @exception IllegalArgumentException * if invoked multiple times */ public final void addMessage(String[] qos) throws XmlBlasterException { if (!msgVec.isEmpty()) throw new IllegalArgumentException(ME + ".addQos() may only be invoked once"); for (int ii = 0; ii < qos.length; ii++) { MsgUnitRaw msg = new MsgUnitRaw(null, (byte[]) null, qos[ii]); msgVec.add(msg); } } /** @see #addMessage(String[] qos) */ public final void addQos(String[] qos) throws XmlBlasterException { addMessage(qos); } /** * Returns all messages in a Vector */ public final Vector getMessages() { return msgVec; } /** * Returns all messages as an array. * * @return Never null */ public final MsgUnitRaw[] getMessageArr() { if (msgVec.isEmpty()) return new MsgUnitRaw[0]; MsgUnitRaw[] arr = new MsgUnitRaw[msgVec.size()]; for (int ii = 0; ii < msgVec.size(); ii++) { arr[ii] = (MsgUnitRaw) msgVec.elementAt(ii); // JDK 1.1 compatible } return arr; } /** * Response is usually only a QoS * * @exception IllegalArgumentException * if there is no QoS to get */ public final String getQos() { /* * OK for empty get() return if (msgVec.isEmpty()) { throw new * IllegalArgumentException(ME + ": getQos() is called without having a * response"); } */ if (msgVec.isEmpty()) { return null; } MsgUnitRaw msg = (MsgUnitRaw) msgVec.elementAt(0); return msg.getQos(); } /** * Response is usually only a QoS * * @exception IllegalArgumentException * if there is no QoS to get */ public final String[] getQosArr() { Vector msgs = getMessages(); String[] strArr = new String[msgs.size()]; for (int ii = 0; ii < strArr.length; ii++) { strArr[ii] = ((MsgUnitRaw) msgs.elementAt(ii)).getQos(); } return strArr; } /** * On errors. * * @exception IllegalArgumentException * if there is no exception to get */ public final XmlBlasterException getException() { if (msgVec.isEmpty()) { throw new IllegalArgumentException(ME + ": getException() is called without having an exception"); } MsgUnitRaw msg = (MsgUnitRaw) msgVec.elementAt(0); if (msg.getContent() == null || msg.getContent().length == 0) { // For example when using XmlInterpreter // <qos><state id='ERROR' info='communication'/></qos> ErrorCode errorCode = ErrorCode.INTERNAL; // default setting try{ // See serialization in XmlScriptInterpreter.java StatusQosData data = glob.getStatusQosFactory().readObject(msg.getQos()); errorCode = ErrorCode.toErrorCode(data.getStateInfo()); } catch (Throwable e) { log.severe("Unexpected exception markup in: '" + msg.getQos() + "': " + e.toString()); } XmlBlasterException e = new XmlBlasterException(glob, errorCode, ME, ""); e.isServerSide(!glob.isServerSide()); // mark to be from the other side return e; } return XmlBlasterException.parseByteArr(glob, msg.getContent(), ErrorCode.USER_UPDATE_INTERNALERROR); } /** * Calculates the length of user data including null bytes and len field * * @exception IllegalArgumentException * Message size is limited to Integer.MAX_VALUE bytes */ long getUserDataLen() { long len = 0L; for (int ii = 0; ii < msgVec.size(); ii++) { MsgUnitRaw unit = (MsgUnitRaw) msgVec.elementAt(ii); len += unit.size() + 3; // three null bytes String tmp = "" + unit.getContent().length; len += tmp.length(); } if (len > Integer.MAX_VALUE) throw new IllegalArgumentException(ME + ": Message size is limited to " + Integer.MAX_VALUE + " bytes"); return len; } /** * The number of bytes of qos+key+content */ public long size() { MsgUnitRaw[] msgs = getMessageArr(); long size = 0; for (int i = 0; i < msgs.length; i++) size += msgs[i].size(); return size; } /** * @param byte4 * The byte4 to set. */ public void setByte4(byte byte4) { this.byte4 = byte4; } /** * @param byte5 * The byte5 to set. */ public void setByte5(byte byte5) { this.byte5 = byte5; } /** * @return Returns the version. */ public int getVersion() { return this.version; } /** * @param version * The version to set. */ public void setVersion(int version) { this.version = version; } /* * @return Returns the sessionId. public String getSessionId() { return * this.sessionId; } */ /* * @param sessionId The sessionId to set. public void setSessionId(String * sessionId) { this.sessionId = sessionId; } */ /** * @return Returns the checksum. */ public boolean isChecksum() { return this.checksum; } /** * @return Returns the compressed. */ public boolean isCompressed() { return this.compressed; } /** * @param className * Can be null * @param pluginConfig Can be null * @return Returns the msgInfoParser. */ public I_MsgInfoParser getMsgInfoParser(String className, I_PluginConfig pluginConfig) throws XmlBlasterException { if (this.msgInfoParser == null) { this.pluginConfig = pluginConfig; if (className == null && this.pluginConfig != null) className = (String)this.pluginConfig.getParameters().get("parserClass"); this.msgInfoParser = MsgInfoParserFactory.instance().getMsgInfoParser( glob, this.progressListener, className, pluginConfig); // new XbfParser(); } return this.msgInfoParser; } /** * @param msgInfoParser * The msgInfoParser to set. */ public void setMsgInfoParser(I_MsgInfoParser msgInfoParser) { this.msgInfoParser = msgInfoParser; } /** * @param msgInfoParser * The msgInfoParser to set. */ public void setMsgInfoParser(String className) throws XmlBlasterException { getMsgInfoParser(className, pluginConfig); } public final String dump() { StringBuffer buffer = new StringBuffer(256); // buffer.append("msgLength=" + buf.buf.length); buffer.append(", checksum=" + checksum); buffer.append(", compressed=" + compressed); buffer.append(", type=" + type); buffer.append(", byte4=" + byte4); buffer.append(", byte5=" + byte5); buffer.append(", version=" + version); buffer.append(", requestId=" + requestId); buffer.append(", methodName=" + methodName); buffer.append(", sessionId=" + sessionId); // buffer.append(", lenUnzipped=" + lenUnzipped); // buffer.append(", checkSumResult=" + checkSumResult); return buffer.toString(); } /** * Get the raw messages as a string, for tests and for dumping only * * @return The stringified message, null bytes are replaced by '*' */ public final String toLiteral() throws XmlBlasterException { return getMsgInfoParser(null, pluginConfig).toLiteral(this); } public static String toLiteral(byte[] rawMsg) throws XmlBlasterException { I_MsgInfoParser parser = MsgInfoParserFactory.instance() .getMsgInfoParser(Global.instance(), null, null, null); return parser.toLiteral(rawMsg); } /** * Access the serialized message, ready to send over the wire. * * @return * @throws XmlBlasterException */ public final byte[] createRawMsg() throws XmlBlasterException { return getMsgInfoParser(null, this.pluginConfig).createRawMsg(this); } /** * Access the serialized message, ready to send over the wire. * * @param className The parser/serializer to use * @return * @throws XmlBlasterException */ public final byte[] createRawMsg(String className) throws XmlBlasterException { return getMsgInfoParser(className, this.pluginConfig).createRawMsg(this); } /** * Convenience method. * * @param in * @param className Class implementing I_MsgInfoParser * Can be null to choose the default parser * @return Never null, usually of length==1 */ public static MsgInfo[] parse(Global glob, I_ProgressListener progressListener, InputStream in, String className, I_PluginConfig pluginConfig) throws IOException, XmlBlasterException { I_MsgInfoParser parser = MsgInfoParserFactory.instance() .getMsgInfoParser(glob, progressListener, className, pluginConfig); return parser.parse(in); } /** * Convenience method. * * @param className Class implementing I_MsgInfoParser * Can be null to choose the default parser * @param pluginConfig The configuration of the plugin, can be null * @return Never null, usually of length==1 */ public static MsgInfo[] parse(Global glob, I_ProgressListener progressListener, byte[] rawMsg, String className, I_PluginConfig pluginConfig) throws IOException, XmlBlasterException { //log.finer(new String(rawMsg)); return parse(glob, progressListener, new ByteArrayInputStream(rawMsg), className, pluginConfig); } /** * @return Returns the bounceObjects, is null if none is available */ public Map getBounceObjects() { return this.bounceObjects; } /** * @return Returns the bounceObjects of type AttachmentHolder, * is never null */ public AttachmentHolder[] getBounceAttachments() { if (this.bounceObjects == null) return new AttachmentHolder[0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -