/**
  * Removes the next value from the buffer, waiting until an object is
  * added for up to the specified timeout value if the buffer is empty.
  *
  * @param timeout  the timeout value in milliseconds
  * @throws BufferUnderflowException if an interrupt is received
  * @throws BufferUnderflowException if the timeout expires
  * @since Commons Collections 3.2
  */
 public Object remove(long timeout)
 {
     lock (lockJ)
     {
         long expiration = java.lang.SystemJ.currentTimeMillis() + timeout;
         long timeLeft   = expiration - java.lang.SystemJ.currentTimeMillis();
         while (timeLeft > 0 && collection.isEmpty())
         {
             try
             {
                 lockJ.wait(timeLeft);
                 timeLeft = expiration - java.lang.SystemJ.currentTimeMillis();
             }
             catch (java.lang.InterruptedException e)
             {
                 java.io.PrintWriter outJ = new java.io.PrintWriter(new java.io.StringWriter());
                 e.printStackTrace(outJ);
                 throw new BufferUnderflowException("Caused by InterruptedException: " + outJ.toString());
             }
         }
         if (collection.isEmpty())
         {
             throw new BufferUnderflowException("Timeout expired");
         }
         return(getBuffer().remove());
     }
 }
 /**
  * Removes the next value from the buffer, waiting until an object is
  * added if the buffer is empty. This method uses the default timeout
  * set in the constructor.
  *
  * @throws BufferUnderflowException if an interrupt is received
  */
 public override Object remove()
 {
     lock (lockJ)
     {
         while (collection.isEmpty())
         {
             try
             {
                 if (timeout <= 0)
                 {
                     lockJ.wait();
                 }
                 else
                 {
                     return(remove(timeout));
                 }
             }
             catch (java.lang.InterruptedException e)
             {
                 java.io.PrintWriter outJ = new java.io.PrintWriter(new java.io.StringWriter());
                 e.printStackTrace(outJ);
                 throw new BufferUnderflowException("Caused by InterruptedException: " + outJ.toString());
             }
         }
         return(getBuffer().remove());
     }
 }
Esempio n. 3
0
        /**
         * Writes a printable representation of this {@code Throwable}'s stack trace
         * to the specified print writer. If the {@code Throwable} contains a
         * {@link #getCause() cause}, the method will be invoked recursively for the
         * nested {@code Throwable}.
         *
         * @param err
         *            the writer to write the stack trace on.
         */
        public virtual void printStackTrace(java.io.PrintWriter err)
        {
            err.println(this.ToString());
            // Don't use getStackTrace() as it calls clone()
            // Get stackTrace, in case stackTrace is reassigned
            StackTraceElement[] stack = getInternalStackTrace();
            foreach (StackTraceElement element in stack)
            {
                err.println("\tat " + element);
            }

            StackTraceElement[] parentStack = stack;
            Throwable           throwable   = getCause();

            while (throwable != null)
            {
                err.print("Caused by: ");
                err.println(throwable);
                StackTraceElement[] currentStack = throwable.getInternalStackTrace();
                int duplicates = countDuplicates(currentStack, parentStack);
                for (int i = 0; i < currentStack.Length - duplicates; i++)
                {
                    err.println("\tat " + currentStack[i]);
                }
                if (duplicates > 0)
                {
                    err.println("\t... " + duplicates + " more");
                }
                parentStack = currentStack;
                throwable   = throwable.getCause();
            }
        }
Esempio n. 4
0
        /*
         * Converts a {@link LogRecord} object into a human readable string
         * representation.
         *
         * @param r
         *            the log record to be formatted into a string.
         * @return the formatted string.
         */

        public override String format(LogRecord r)
        {
            java.lang.StringBuilder sb = new java.lang.StringBuilder();
            sb.append(java.text.MessageFormat.format("{0, date} {0, time} ", //$NON-NLS-1$
                                                     new Object[] { new java.util.Date(r.getMillis()) }));
            sb.append(r.getSourceClassName()).append(" ");                   //$NON-NLS-1$
            sb.append(r.getSourceMethodName()).append(java.lang.SystemJ.getProperty("line.separator"));
            sb.append(r.getLevel().getName()).append(": ");                  //$NON-NLS-1$
            sb.append(formatMessage(r)).append(java.lang.SystemJ.getProperty("line.separator"));
            if (null != r.getThrown())
            {
                sb.append("Throwable occurred: "); //$NON-NLS-1$
                java.lang.Throwable t  = r.getThrown();
                java.io.PrintWriter pw = null;
                try {
                    java.io.StringWriter sw = new java.io.StringWriter();
                    pw = new java.io.PrintWriter(sw);
                    t.printStackTrace(pw);
                    sb.append(sw.toString());
                } finally {
                    if (pw != null)
                    {
                        try {
                            pw.close();
                        } catch (Exception e) {
                            // ignore
                        }
                    }
                }
            }
            return(sb.toString());
        }
Esempio n. 5
0
 /**
  * Converts a {@link LogRecord} object into a human readable string
  * representation.
  *
  * @param r
  *            the log record to be formatted into a string.
  * @return the formatted string.
  */
 public override String format(LogRecord r)
 {
     java.lang.StringBuilder sb = new java.lang.StringBuilder();
     sb.append(java.text.MessageFormat.format("{0, date} {0, time} ", //$NON-NLS-1$
         new Object[] { new java.util.Date(r.getMillis()) }));
     sb.append(r.getSourceClassName()).append(" "); //$NON-NLS-1$
     sb.append(r.getSourceMethodName()).append(java.lang.SystemJ.getProperty("line.separator"));
     sb.append(r.getLevel().getName()).append(": "); //$NON-NLS-1$
     sb.append(formatMessage(r)).append(java.lang.SystemJ.getProperty("line.separator"));
     if (null != r.getThrown()) {
     sb.append("Throwable occurred: "); //$NON-NLS-1$
     java.lang.Throwable t = r.getThrown();
     java.io.PrintWriter pw = null;
     try {
         java.io.StringWriter sw = new java.io.StringWriter();
         pw = new java.io.PrintWriter(sw);
         t.printStackTrace(pw);
         sb.append(sw.toString());
     } finally {
         if (pw != null) {
             try {
                 pw.close();
             } catch (Exception e) {
                 // ignore
             }
         }
     }
     }
     return sb.toString();
 }
Esempio n. 6
0
 /**
  * Prints this <code>KeySelectorException</code>, its backtrace and
  * the cause's backtrace to the specified print writer.
  *
  * @param s <code>PrintWriter</code> to use for output
  */
 public override void printStackTrace(java.io.PrintWriter s)
 {
     base.printStackTrace(s);
     if (cause != null)
     {
         cause.printStackTrace(s);
     }
 }
 /**
  * Prints the stack trace of this exception to the specified stream.
  *
  * @param out  the <code>PrintStream</code> to use for output
  */
 public override void printStackTrace(java.lang.PrintStream outJ)
 {
     lock (outJ)
     {
         java.io.PrintWriter pw = new java.io.PrintWriter(outJ, false);
         printStackTrace(pw);
         // Flush the PrintWriter before it's GC'ed.
         pw.flush();
     }
 }
 /**
  * Prints the stack trace of this exception to the specified writer.
  *
  * @param out  the <code>PrintWriter</code> to use for output
  */
 public override void printStackTrace(java.io.PrintWriter outJ)
 {
     lock (outJ)
     {
         base.printStackTrace(outJ);
         if (rootCause != null && JDK_SUPPORTS_NESTED == false)
         {
             outJ.print("Caused by: ");
             rootCause.printStackTrace(outJ);
         }
     }
 }
Esempio n. 9
0
        private void timeoutWait(int nAdditions)
        {
            // method synchronized by callers
            if (nAdditions > maximumSize)
            {
                throw new BufferOverflowException(
                          "Buffer size cannot exceed " + maximumSize);
            }
            if (timeout <= 0)
            {
                // no wait period (immediate timeout)
                if (getBuffer().size() + nAdditions > maximumSize)
                {
                    throw new BufferOverflowException(
                              "Buffer size cannot exceed " + maximumSize);
                }
                return;
            }
            long expiration = java.lang.SystemJ.currentTimeMillis() + timeout;
            long timeLeft   = expiration - java.lang.SystemJ.currentTimeMillis();

            while (timeLeft > 0 && getBuffer().size() + nAdditions > maximumSize)
            {
                try
                {
                    lockJ.wait(timeLeft);
                    timeLeft = expiration - java.lang.SystemJ.currentTimeMillis();
                }
                catch (java.lang.InterruptedException ex)
                {
                    java.io.PrintWriter outJ = new java.io.PrintWriter(new java.io.StringWriter());
                    ex.printStackTrace(outJ);
                    throw new BufferUnderflowException(
                              "Caused by InterruptedException: " + outJ.toString());
                }
            }
            if (getBuffer().size() + nAdditions > maximumSize)
            {
                throw new BufferOverflowException("Timeout expired");
            }
        }
Esempio n. 10
0
        /*
         * Print the the trace of methods from where the error
         * originated.  This will trace all nested exception
         * objects, as well as this object.
         * @param s The writer where the dump will be sent to.
         */
        public override void printStackTrace(java.io.PrintWriter s)
        {
            if (s == null)
            {
                s = new java.io.PrintWriter(java.lang.SystemJ.err, true);
            }

            try {
                String locInfo = getLocationAsString();

                if (null != locInfo)
                {
                    s.println(locInfo);
                }

                base.printStackTrace(s);
            } catch (java.lang.Throwable e) {}

            // BASTIE: isJDK140Higher always true :)

            // insure output is written
            s.flush();
        }
 private void timeoutWait(int nAdditions)
 {
     // method synchronized by callers
     if (nAdditions > maximumSize)
     {
         throw new BufferOverflowException(
                 "Buffer size cannot exceed " + maximumSize);
     }
     if (timeout <= 0)
     {
         // no wait period (immediate timeout)
         if (getBuffer().size() + nAdditions > maximumSize)
         {
             throw new BufferOverflowException(
                     "Buffer size cannot exceed " + maximumSize);
         }
         return;
     }
     long expiration = java.lang.SystemJ.currentTimeMillis() + timeout;
     long timeLeft = expiration - java.lang.SystemJ.currentTimeMillis();
     while (timeLeft > 0 && getBuffer().size() + nAdditions > maximumSize)
     {
         try
         {
             lockJ.wait(timeLeft);
             timeLeft = expiration - java.lang.SystemJ.currentTimeMillis();
         }
         catch (java.lang.InterruptedException ex)
         {
             java.io.PrintWriter outJ = new java.io.PrintWriter(new java.io.StringWriter());
             ex.printStackTrace(outJ);
             throw new BufferUnderflowException(
                 "Caused by InterruptedException: " + outJ.toString());
         }
     }
     if (getBuffer().size() + nAdditions > maximumSize)
     {
         throw new BufferOverflowException("Timeout expired");
     }
 }
Esempio n. 12
0
 /**
  * Prints this <code>MarshalException</code>, its backtrace and
  * the cause's backtrace to the specified print writer.
  *
  * @param s <code>PrintWriter</code> to use for output
  */
 public override void printStackTrace(java.io.PrintWriter s)
 {
     base.printStackTrace(s);
     cause.printStackTrace(s);
 }
 /**
  * Prints the stack trace of this exception to the specified stream.
  *
  * @param out  the <code>PrintStream</code> to use for output
  */
 public override void printStackTrace(java.lang.PrintStream outJ)
 {
     lock (outJ)
     {
         java.io.PrintWriter pw = new java.io.PrintWriter(outJ, false);
         printStackTrace(pw);
         // Flush the PrintWriter before it's GC'ed.
         pw.flush();
     }
 }
Esempio n. 14
0
 /**
  * Sets the {@code PrintWriter} that is used by all loaded drivers, and also
  * the {@code DriverManager}.
  *
  * @param out
  *            the {@code PrintWriter} to be used.
  */
 public static void setLogWriter(java.io.PrintWriter outJ)
 {
     checkLogSecurity();
     thePrintWriter = outJ;
 }
Esempio n. 15
0
 /**
  * Sets the {@code PrintWriter} that is used by all loaded drivers, and also
  * the {@code DriverManager}.
  *
  * @param out
  *            the {@code PrintWriter} to be used.
  */
 public static void setLogWriter(java.io.PrintWriter outJ)
 {
     checkLogSecurity();
     thePrintWriter = outJ;
 }
 /**
  * Removes the next value from the buffer, waiting until an object is
  * added if the buffer is empty. This method uses the default timeout
  * set in the constructor.
  *
  * @throws BufferUnderflowException if an interrupt is received
  */
 public override Object remove()
 {
     lock (lockJ)
     {
         while (collection.isEmpty())
         {
             try
             {
                 if (timeout <= 0)
                 {
                     lockJ.wait();
                 }
                 else
                 {
                     return remove(timeout);
                 }
             }
             catch (java.lang.InterruptedException e)
             {
                 java.io.PrintWriter outJ = new java.io.PrintWriter(new java.io.StringWriter());
                 e.printStackTrace(outJ);
                 throw new BufferUnderflowException("Caused by InterruptedException: " + outJ.toString());
             }
         }
         return getBuffer().remove();
     }
 }
 /**
  * Removes the next value from the buffer, waiting until an object is
  * added for up to the specified timeout value if the buffer is empty.
  *
  * @param timeout  the timeout value in milliseconds
  * @throws BufferUnderflowException if an interrupt is received
  * @throws BufferUnderflowException if the timeout expires
  * @since Commons Collections 3.2
  */
 public Object remove(long timeout)
 {
     lock (lockJ)
     {
         long expiration = java.lang.SystemJ.currentTimeMillis() + timeout;
         long timeLeft = expiration - java.lang.SystemJ.currentTimeMillis();
         while (timeLeft > 0 && collection.isEmpty())
         {
             try
             {
                 lockJ.wait(timeLeft);
                 timeLeft = expiration - java.lang.SystemJ.currentTimeMillis();
             }
             catch (java.lang.InterruptedException e)
             {
                 java.io.PrintWriter outJ = new java.io.PrintWriter(new java.io.StringWriter());
                 e.printStackTrace(outJ);
                 throw new BufferUnderflowException("Caused by InterruptedException: " + outJ.toString());
             }
         }
         if (collection.isEmpty())
         {
             throw new BufferUnderflowException("Timeout expired");
         }
         return getBuffer().remove();
     }
 }
Esempio n. 18
0
        /**
         * Print the the trace of methods from where the error
         * originated.  This will trace all nested exception
         * objects, as well as this object.
         * @param s The writer where the dump will be sent to.
         */
        public override void printStackTrace(java.io.PrintWriter s)
        {
            if (s == null) {
            s = new java.io.PrintWriter(java.lang.SystemJ.err, true);
            }

            try {
            String locInfo = getLocationAsString();

            if (null != locInfo) {
                s.println(locInfo);
            }

            base.printStackTrace(s);
            } catch (java.lang.Throwable e) {}

            // BASTIE: isJDK140Higher always true :)

            // insure output is written
            s.flush();
        }