List of usage examples for java.io EOFException getMessage
public String getMessage()
From source file:com.amazon.sqs.javamessaging.message.SQSBytesMessage.java
/** * Reads a 64-bit integer from the bytes message stream. * /* w w w . j av a 2s . c o m*/ * @return a 64-bit integer value from the bytes message stream, interpreted as a long * @throws JMSException * If the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * If unexpected end of bytes stream has been reached. * @throws MessageNotReadableException * If the message is in write-only mode. */ @Override public long readLong() throws JMSException { checkCanRead(); try { return dataIn.readLong(); } catch (EOFException e) { throw new MessageEOFException(e.getMessage()); } catch (IOException e) { throw convertExceptionToJMSException(e); } }
From source file:com.amazon.sqs.javamessaging.message.SQSBytesMessage.java
/** * Reads a <code>float</code> from the bytes message stream. * //from ww w . ja v a2s . c o m * @return a <code>float</code> value from the bytes message stream * @throws JMSException * If the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * If unexpected end of bytes stream has been reached. * @throws MessageNotReadableException * If the message is in write-only mode. */ @Override public float readFloat() throws JMSException { checkCanRead(); try { return dataIn.readFloat(); } catch (EOFException e) { throw new MessageEOFException(e.getMessage()); } catch (IOException e) { throw convertExceptionToJMSException(e); } }
From source file:com.amazon.sqs.javamessaging.message.SQSBytesMessage.java
/** * Reads a <code>double</code> from the bytes message stream. * /* w w w .j a v a 2 s . c om*/ * @return a <code>double</code> value from the bytes message stream * @throws JMSException * If the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * If unexpected end of bytes stream has been reached. * @throws MessageNotReadableException * If the message is in write-only mode. */ @Override public double readDouble() throws JMSException { checkCanRead(); try { return dataIn.readDouble(); } catch (EOFException e) { throw new MessageEOFException(e.getMessage()); } catch (IOException e) { throw convertExceptionToJMSException(e); } }
From source file:com.amazon.sqs.javamessaging.message.SQSBytesMessage.java
/** * Reads a string that has been encoded using a UTF-8 format from * the bytes message stream/*from w w w. jav a2 s . c o m*/ * * @return a Unicode string from the bytes message stream * @throws JMSException * If the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * If unexpected end of bytes stream has been reached. * @throws MessageNotReadableException * If the message is in write-only mode. */ @Override public String readUTF() throws JMSException { checkCanRead(); try { return dataIn.readUTF(); } catch (EOFException e) { throw new MessageEOFException(e.getMessage()); } catch (IOException e) { throw convertExceptionToJMSException(e); } }
From source file:org.cloudata.core.common.ipc.CClient.java
/** * Make a call, passing <code>param</code>, to the IPC server running at * <code>address</code>, returning the value. Throws exceptions if there are * network problems or if the remote code threw an exception. *//*from ww w . j a v a 2 s .c o m*/ public CWritable call(CWritable param, InetSocketAddress address) throws InterruptedException, IOException { Connection connection = getConnection(address); Call call = new Call(param); int retryCount = 0; while (true) { try { connection.sendParam(call); break; } catch (IOException e) { if (retryCount > 5) { LOG.error("SendParam error:" + address + "," + e.getMessage(), e); throw e; } LOG.error("SendParam error:" + address + "," + e.getMessage() + ", but retry:" + retryCount); retryCount++; closeThisConnection(address, connection); // close on error connection = getConnection(address); } } try { int id; try { id = connection.in.readInt(); // try to read an id } catch (SocketTimeoutException e) { throw new SocketTimeoutException( "timed out waiting for rpc response[" + address + "]" + new Date(call.lastActivity)); } boolean isError = connection.in.readBoolean(); // read if error if (isError) { String exceptionClassName = CWritableUtils.readString(connection.in); String exceptionMessage = CWritableUtils.readString(connection.in); this.returnToConnections(address, connection); throw new CRemoteException(exceptionClassName, exceptionMessage); } else { CWritable value = (CWritable) ReflectionUtils.newInstance(valueClass, conf); value.readFields(connection.in); // read value this.returnToConnections(address, connection); return value; } } catch (EOFException eof) { //LOG.warn("EOFException: id : " + connection + ", socket : " + connection.socket, eof); closeThisConnection(address, connection); throw new IOException(eof.getMessage(), eof); } catch (CRemoteException e) { throw e; } catch (SocketTimeoutException e) { throw e; } catch (Exception e) { LOG.error("Error while call:" + connection.address + "," + e.getMessage(), e); IOException err = new IOException(e.getMessage()); err.initCause(e); closeThisConnection(address, connection); throw err; } // try { // synchronized (call) { // connection.sendParam(call); // send the parameter // long wait = timeout; // do { // call.wait(wait); // wait for the result // wait = timeout - (System.currentTimeMillis() - call.lastActivity); // } while (!call.done && wait > 0); // // if (call.error != null) { // throw new NRemoteException(call.errorClass, call.error); // } else if (!call.done) { // // FIXME timeout? ? ? timeout? ? // throw new SocketTimeoutException("timed out waiting for rpc response[" // + address + "]" + new Date(call.lastActivity)); // } else { // return call.value; // } // } // } finally { // connection.decrementRef(); // returnToConnections(address, connection); // } }
From source file:kr.co.bitnine.octopus.frame.Session.java
private void messageLoop() throws Exception { boolean doingExtendedQueryMessage = false; boolean ignoreTillSync = false; boolean sendReadyForQuery = true; while (true) { try {/* ww w. j ava 2s . co m*/ doingExtendedQueryMessage = false; if (sendReadyForQuery) { LOG.debug("send ReadyForQuery message"); Message msg = Message.builder('Z').putChar(TransactionStatus.IDLE.getIndicator()).build(); messageStream.putMessageAndFlush(msg); sendReadyForQuery = false; } Message msg = messageStream.getMessage(); char type = msg.getType(); switch (type) { case 'Q': break; case 'P': case 'B': case 'E': case 'C': case 'D': case 'H': LOG.debug("extended query sub-protocol message"); doingExtendedQueryMessage = true; break; case 'S': case 'X': ignoreTillSync = false; break; case 'd': case 'c': case 'f': break; default: PostgresErrorData edata = new PostgresErrorData(PostgresSeverity.FATAL, PostgresSQLState.PROTOCOL_VIOLATION, "invalid frontend message type '" + type + "'"); new OctopusException(edata).emitErrorReport(); } if (ignoreTillSync) { LOG.debug("ignore message(type='" + type + "') till Sync message"); continue; } switch (type) { case 'Q': cancelContext.enterCancel(); handleQuery(msg); cancelContext.exitCancel(); sendReadyForQuery = true; break; case 'P': cancelContext.enterCancel(); handleParse(msg); break; case 'B': handleBind(msg); break; case 'E': handleExecute(msg); break; case 'C': handleClose(msg); break; case 'D': handleDescribe(msg); break; case 'H': LOG.debug("handle Flush message"); messageStream.flush(); break; case 'S': LOG.debug("handle Sync message"); cancelContext.exitCancel(); sendReadyForQuery = true; break; case 'X': LOG.info("Terminate received"); return; case 'd': // copy data case 'c': // copy done case 'f': // copy fail break; // ignore these messages default: PostgresErrorData edata = new PostgresErrorData(PostgresSeverity.FATAL, PostgresSQLState.PROTOCOL_VIOLATION, "invalid frontend message type '" + type + "'"); new OctopusException(edata).emitErrorReport(); } } catch (OctopusException oe) { switch (oe.getErrorData().getSeverity()) { case PANIC: // exit Octopus LOG.fatal(ExceptionUtils.getStackTrace(oe)); System.exit(0); break; case FATAL: // exit Session throw oe; case ERROR: LOG.error(ExceptionUtils.getStackTrace(oe)); cancelContext.exitCancel(); break; default: throw new RuntimeException("could not reach here"); } // ERROR if (doingExtendedQueryMessage) { LOG.debug("ignore till Sync message"); ignoreTillSync = true; } if (!ignoreTillSync) sendReadyForQuery = true; } catch (EOFException eofe) { PostgresErrorData edata = new PostgresErrorData(PostgresSeverity.FATAL, PostgresSQLState.PROTOCOL_VIOLATION, eofe.getMessage()); emitErrorReport(edata); throw eofe; } } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Reads a <code>boolean</code> from the stream message. * * @return the <code>boolean</code> value read * @throws JMSException//from w w w .j a v a 2 s. co m * if the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * if unexpected end of message stream has been reached. * @throws MessageFormatException * if this type conversion is invalid. * @throws javax.jms.MessageNotReadableException * if the message is in write-only mode. */ public boolean readBoolean() throws JMSException { initializeReading(); try { this.dataIn.mark(10); int type = this.dataIn.read(); if (type == -1) { throw new MessageEOFException("reached end of data"); } if (type == MarshallingSupport.BOOLEAN_TYPE) { return this.dataIn.readBoolean(); } if (type == MarshallingSupport.STRING_TYPE) { return Boolean.valueOf(this.dataIn.readUTF()).booleanValue(); } if (type == MarshallingSupport.NULL) { this.dataIn.reset(); throw new NullPointerException("Cannot convert NULL value to boolean."); } else { this.dataIn.reset(); throw new MessageFormatException(" not a boolean type"); } } catch (EOFException e) { String exMessage = "Reached premature EOF: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } catch (IOException e) { String exMessage = "Could not read boolean: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Reads a Unicode character value from the stream message. * * @return a Unicode character from the stream message * @throws JMSException/*from w ww . j ava2 s . co m*/ * if the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * if unexpected end of message stream has been reached. * @throws MessageFormatException * if this type conversion is invalid * @throws MessageNotReadableException * if the message is in write-only mode. */ public char readChar() throws JMSException { initializeReading(); try { this.dataIn.mark(17); int type = this.dataIn.read(); if (type == -1) { throw new MessageEOFException("reached end of data"); } if (type == MarshallingSupport.CHAR_TYPE) { return this.dataIn.readChar(); } if (type == MarshallingSupport.NULL) { this.dataIn.reset(); throw new NullPointerException("Cannot convert NULL value to char."); } else { this.dataIn.reset(); throw new MessageFormatException(" not a char type"); } } catch (NumberFormatException mfe) { try { this.dataIn.reset(); } catch (IOException ioe) { JMSException jmsEx = new MessageFormatException(ioe.getMessage()); jmsEx.setLinkedException(ioe); throw jmsEx; } throw mfe; } catch (EOFException e) { String exMessage = "Reached premature EOF: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } catch (IOException e) { String exMessage = "Could not read boolean: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Reads a <code>byte</code> value from the stream message. * * @return the next byte from the stream message as a 8-bit * <code>byte</code> * @throws JMSException// w ww . ja va 2 s. c om * if the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * if unexpected end of message stream has been reached. * @throws MessageFormatException * if this type conversion is invalid. * @throws javax.jms.MessageNotReadableException * if the message is in write-only mode. */ public byte readByte() throws JMSException { initializeReading(); try { this.dataIn.mark(10); int type = this.dataIn.read(); if (type == -1) { throw new MessageEOFException("reached end of data"); } if (type == MarshallingSupport.BYTE_TYPE) { return this.dataIn.readByte(); } if (type == MarshallingSupport.STRING_TYPE) { return Byte.valueOf(this.dataIn.readUTF()).byteValue(); } if (type == MarshallingSupport.NULL) { this.dataIn.reset(); throw new NullPointerException("Cannot convert NULL value to byte."); } else { this.dataIn.reset(); throw new MessageFormatException(" not a byte type"); } } catch (NumberFormatException mfe) { try { this.dataIn.reset(); } catch (IOException ioe) { JMSException jmsEx = new MessageFormatException(ioe.getMessage()); jmsEx.setLinkedException(ioe); throw jmsEx; } throw mfe; } catch (EOFException e) { String exMessage = "Reached premature EOF: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } catch (IOException e) { String exMessage = "Could not read boolean: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Reads a <code>float</code> from the stream message. * * @return a <code>float</code> value from the stream message * @throws JMSException/*w ww. j a v a 2 s . co m*/ * if the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * if unexpected end of message stream has been reached. * @throws MessageFormatException * if this type conversion is invalid. * @throws MessageNotReadableException * if the message is in write-only mode. */ public float readFloat() throws JMSException { initializeReading(); try { this.dataIn.mark(33); int type = this.dataIn.read(); if (type == -1) { throw new MessageEOFException("reached end of data"); } if (type == MarshallingSupport.FLOAT_TYPE) { return this.dataIn.readFloat(); } if (type == MarshallingSupport.STRING_TYPE) { return Float.valueOf(this.dataIn.readUTF()).floatValue(); } if (type == MarshallingSupport.NULL) { this.dataIn.reset(); throw new NullPointerException("Cannot convert NULL value to float."); } else { this.dataIn.reset(); throw new MessageFormatException(" not a float type"); } } catch (NumberFormatException mfe) { try { this.dataIn.reset(); } catch (IOException ioe) { JMSException jmsEx = new MessageFormatException(ioe.getMessage()); jmsEx.setLinkedException(ioe); throw jmsEx; } throw mfe; } catch (EOFException e) { String exMessage = "Reached premature EOF: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } catch (IOException e) { String exMessage = "Could not read boolean: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }