Java Doc for CircularObjectBuffer.java in  » Template-Engine » ostermillerutils » com » Ostermiller » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Template Engine » ostermillerutils » com.Ostermiller.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.Ostermiller.util.CircularObjectBuffer

CircularObjectBuffer
public class CircularObjectBuffer (Code)
Implements the Circular Buffer producer/consumer model for Objects. More information about this class is available from ostermiller.org.

This class is thread safe.
See Also:   CircularCharBuffer
See Also:   CircularByteBuffer
author:
   Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities<
Parameters:
  ElementType - > Type of object allowed in this circular buffer
since:
   ostermillerutils 1.00.00



Field Summary
final public static  intINFINITE_SIZE
     A buffer that will grow as things are added.
protected  booleanblockingWrite
    
protected  ElementType[]buffer
     The circular buffer.

The actual capacity of the buffer is one less than the actual length of the buffer so that an empty and a full buffer can be distinguished.

protected volatile  booleaninfinite
    
protected  booleaninputDone
     True when no more input is coming into this buffer.
protected volatile  intreadPosition
     Index of the first Object available to be read.
protected volatile  intwritePosition
     Index of the first Object available to be written.

Constructor Summary
public  CircularObjectBuffer()
     Create a new buffer with a default capacity.
public  CircularObjectBuffer(int size)
     Create a new buffer with given capacity.
public  CircularObjectBuffer(boolean blockingWrite)
     Create a new buffer with a default capacity and given blocking behavior.
public  CircularObjectBuffer(int size, boolean blockingWrite)
     Create a new buffer with the given capacity and blocking behavior.

Method Summary
public  voidclear()
     Make this buffer ready for reuse.
public  voiddone()
     This method should be used by the producer to signal to the consumer that the producer is done producing objects and that the consumer should stop asking for objects once it has used up buffered objects.

Once the producer has signaled that it is done, further write() invocations will cause an IllegalStateException to be thrown.

public  intgetAvailable()
     Get number of Objects that are available to be read.
public  intgetSize()
     Get the capacity of this buffer.
public  intgetSpaceLeft()
     Get the number of Objects this buffer has free for writing.
public  ElementTyperead()
     Get a single Object from this buffer.
public  intread(ElementType[] buf)
     Get Objects into an array from this buffer.
public  intread(ElementType[] buf, int off, int len)
     Get Objects into a portion of an array from this buffer.
public  longskip(long n)
     Skip Objects.
public  voidwrite(ElementType[] buf)
     Fill this buffer with array of Objects.
public  voidwrite(ElementType[] buf, int off, int len)
     Fill this buffer with a portion of an array of Objects. This method should be called by the producer. If the buffer allows blocking writes, this method will block until all the data has been written rather than throw an IOException.
Parameters:
  buf - Array of Objects
Parameters:
  off - Offset from which to start writing Objects
Parameters:
  len - - Number of Objects to write
throws:
  BufferOverflowException - if buffer does not allow blocking writesand the buffer is full.
public  voidwrite(ElementType o)
     Add a single Object to this buffer.

Field Detail
INFINITE_SIZE
final public static int INFINITE_SIZE(Code)
A buffer that will grow as things are added.
since:
   ostermillerutils 1.00.00



blockingWrite
protected boolean blockingWrite(Code)
True if a write to a full buffer should block until the buffer has room, false if the write method should throw an IOException
since:
   ostermillerutils 1.00.00



buffer
protected ElementType[] buffer(Code)
The circular buffer.

The actual capacity of the buffer is one less than the actual length of the buffer so that an empty and a full buffer can be distinguished. An empty buffer will have the readPostion and the writePosition equal to each other. A full buffer will have the writePosition one less than the readPostion.

There are two important indexes into the buffer: The readPosition, and the writePosition. The Objects available to be read go from the readPosition to the writePosition, wrapping around the end of the buffer. The space available for writing goes from the write position to one less than the readPosition, wrapping around the end of the buffer.
since:
   ostermillerutils 1.00.00




infinite
protected volatile boolean infinite(Code)
If this buffer is infinite (should resize itself when full)
since:
   ostermillerutils 1.00.00



inputDone
protected boolean inputDone(Code)
True when no more input is coming into this buffer. At that point reading from the buffer may return null if the buffer is empty, otherwise a read will block until an Object is available.
since:
   ostermillerutils 1.00.00



readPosition
protected volatile int readPosition(Code)
Index of the first Object available to be read.
since:
   ostermillerutils 1.00.00



writePosition
protected volatile int writePosition(Code)
Index of the first Object available to be written.
since:
   ostermillerutils 1.00.00




Constructor Detail
CircularObjectBuffer
public CircularObjectBuffer()(Code)
Create a new buffer with a default capacity. Writing to a full buffer will block until space is available rather than throw an exception.
since:
   ostermillerutils 1.00.00



CircularObjectBuffer
public CircularObjectBuffer(int size)(Code)
Create a new buffer with given capacity. Writing to a full buffer will block until space is available rather than throw an exception.

Note that the buffer may reserve some Objects for special purposes and capacity number of Objects may not be able to be written to the buffer.

Note that if the buffer is of INFINITE_SIZE it will neither block or throw exceptions, but rather grow without bound.
Parameters:
  size - desired capacity of the buffer in Objects or CircularObjectBuffer.INFINITE_SIZE.
since:
   ostermillerutils 1.00.00




CircularObjectBuffer
public CircularObjectBuffer(boolean blockingWrite)(Code)
Create a new buffer with a default capacity and given blocking behavior.
Parameters:
  blockingWrite - true writing to a full buffer should blockuntil space is available, false if an exception shouldbe thrown instead.
since:
   ostermillerutils 1.00.00



CircularObjectBuffer
public CircularObjectBuffer(int size, boolean blockingWrite)(Code)
Create a new buffer with the given capacity and blocking behavior.

Note that the buffer may reserve some Objects for special purposes and capacity number of Objects may not be able to be written to the buffer.

Note that if the buffer is of INFINITE_SIZE it will neither block or throw exceptions, but rather grow without bound.
Parameters:
  size - desired capacity of the buffer in Objects or CircularObjectBuffer.INFINITE_SIZE.
Parameters:
  blockingWrite - true writing to a full buffer should blockuntil space is available, false if an exception shouldbe thrown instead.
since:
   ostermillerutils 1.00.00





Method Detail
clear
public void clear()(Code)
Make this buffer ready for reuse. The contents of the buffer will be cleared and the streams associated with this buffer will be reopened if they had been closed.
since:
   ostermillerutils 1.00.00



done
public void done()(Code)
This method should be used by the producer to signal to the consumer that the producer is done producing objects and that the consumer should stop asking for objects once it has used up buffered objects.

Once the producer has signaled that it is done, further write() invocations will cause an IllegalStateException to be thrown. Calling done() multiple times, however, has no effect.
since:
   ostermillerutils 1.00.00




getAvailable
public int getAvailable()(Code)
Get number of Objects that are available to be read.

Note that the number of Objects available plus the number of Objects free may not add up to the capacity of this buffer, as the buffer may reserve some space for other purposes. the size in Objects of this buffer
since:
   ostermillerutils 1.00.00




getSize
public int getSize()(Code)
Get the capacity of this buffer.

Note that the number of Objects available plus the number of Objects free may not add up to the capacity of this buffer, as the buffer may reserve some space for other purposes. the size in Objects of this buffer
since:
   ostermillerutils 1.00.00




getSpaceLeft
public int getSpaceLeft()(Code)
Get the number of Objects this buffer has free for writing.

Note that the number of Objects available plus the number of Objects free may not add up to the capacity of this buffer, as the buffer may reserve some space for other purposes. the available space in Objects of this buffer
since:
   ostermillerutils 1.00.00




read
public ElementType read() throws InterruptedException(Code)
Get a single Object from this buffer. This method should be called by the consumer. This method will block until a Object is available or no more objects are available. The Object read, or null if there are no more objects
throws:
  InterruptedException - if the thread is interrupted while waiting.
since:
   ostermillerutils 1.00.00



read
public int read(ElementType[] buf) throws InterruptedException(Code)
Get Objects into an array from this buffer. This method should be called by the consumer. This method will block until some input is available, or there is no more input.
Parameters:
  buf - Destination buffer. The number of Objects read, or -1 there willbe no more objects available.
throws:
  InterruptedException - if the thread is interrupted while waiting.
since:
   ostermillerutils 1.00.00



read
public int read(ElementType[] buf, int off, int len) throws InterruptedException(Code)
Get Objects into a portion of an array from this buffer. This method should be called by the consumer. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
Parameters:
  buf - Destination buffer.
Parameters:
  off - Offset at which to start storing Objects.
Parameters:
  len - Maximum number of Objects to read. The number of Objects read, or -1 there willbe no more objects available.
throws:
  InterruptedException - if the thread is interrupted while waiting.
since:
   ostermillerutils 1.00.00



skip
public long skip(long n) throws InterruptedException, IllegalArgumentException(Code)
Skip Objects. This method should be used by the consumer when it does not care to examine some number of Objects. This method will block until some Objects are available, or there will be no more Objects available.
Parameters:
  n - The number of Objects to skip The number of Objects actually skipped
throws:
  IllegalArgumentException - if n is negative.
throws:
  InterruptedException - if the thread is interrupted while waiting.
since:
   ostermillerutils 1.00.00



write
public void write(ElementType[] buf) throws BufferOverflowException, IllegalStateException, InterruptedException(Code)
Fill this buffer with array of Objects. This method should be called by the producer. If the buffer allows blocking writes, this method will block until all the data has been written rather than throw a BufferOverflowException.
Parameters:
  buf - Array of Objects to be written
throws:
  BufferOverflowException - if buffer does not allow blocking writesand the buffer is full. If the exception is thrown, no datawill have been written since the buffer was set to be non-blocking.
throws:
  IllegalStateException - if done() has been called.
throws:
  InterruptedException - if the write is interrupted.
since:
   ostermillerutils 1.00.00



write
public void write(ElementType[] buf, int off, int len) throws BufferOverflowException, IllegalStateException, InterruptedException(Code)
Fill this buffer with a portion of an array of Objects. This method should be called by the producer. If the buffer allows blocking writes, this method will block until all the data has been written rather than throw an IOException.
Parameters:
  buf - Array of Objects
Parameters:
  off - Offset from which to start writing Objects
Parameters:
  len - - Number of Objects to write
throws:
  BufferOverflowException - if buffer does not allow blocking writesand the buffer is full. If the exception is thrown, no datawill have been written since the buffer was set to be non-blocking.
throws:
  IllegalStateException - if done() has been called.
throws:
  InterruptedException - if the write is interrupted.
since:
   ostermillerutils 1.00.00



write
public void write(ElementType o) throws BufferOverflowException, IllegalStateException, InterruptedException(Code)
Add a single Object to this buffer. This method should be called by the producer. If the buffer allows blocking writes, this method will block until all the data has been written rather than throw an IOException.
Parameters:
  o - Object to be written.
throws:
  BufferOverflowException - if buffer does not allow blocking writesand the buffer is full. If the exception is thrown, no datawill have been written since the buffer was set to be non-blocking.
throws:
  IllegalStateException - if done() has been called.
throws:
  InterruptedException - if the write is interrupted.
since:
   ostermillerutils 1.00.00



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.