partyline

CommonJava top-level parent POM.

License

License

GroupId

GroupId

org.commonjava.util
ArtifactId

ArtifactId

partyline
Last Version

Last Version

2.0
Release Date

Release Date

Type

Type

jar
Description

Description

partyline
CommonJava top-level parent POM.
Source Code Management

Source Code Management

https://github.com/Commonjava/partyline

Download partyline

How to add to project

<!-- https://jarcasting.com/artifacts/org.commonjava.util/partyline/ -->
<dependency>
    <groupId>org.commonjava.util</groupId>
    <artifactId>partyline</artifactId>
    <version>2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.commonjava.util/partyline/
implementation 'org.commonjava.util:partyline:2.0'
// https://jarcasting.com/artifacts/org.commonjava.util/partyline/
implementation ("org.commonjava.util:partyline:2.0")
'org.commonjava.util:partyline:jar:2.0'
<dependency org="org.commonjava.util" name="partyline" rev="2.0">
  <artifact name="partyline" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.commonjava.util', module='partyline', version='2.0')
)
libraryDependencies += "org.commonjava.util" % "partyline" % "2.0"
[org.commonjava.util/partyline "2.0"]

Dependencies

compile (9)

Group / Artifact Type Version
junit : junit jar
commons-io : commons-io jar
org.slf4j : slf4j-api jar
ch.qos.logback : logback-classic jar
commons-lang : commons-lang jar
org.commonjava.cdi.util : weft jar 1.14
org.infinispan : infinispan-commons jar 9.4.7.Final
org.infinispan : infinispan-core jar 9.4.7.Final
org.jboss.logging : jboss-logging jar 3.3.0.Final

test (4)

Group / Artifact Type Version
org.jboss.byteman : byteman jar 3.0.6
org.jboss.byteman : byteman-submit jar 3.0.6
org.jboss.byteman : byteman-install jar 3.0.6
org.jboss.byteman : byteman-bmunit jar 3.0.6

Project Modules

There are no modules declared in this project.

PartyLine Joinable Streams

PartyLine is a tiny library for allowing code to attach ("join") a stream that's already in progress. This is particularly useful on servers that cache content. Caching large files as a result of a user request can easily lead to request timeouts for the user, if the server downloads the content into the cache and then serves it to the user. Even if your server sets up a simple "tee" output stream to simultaneously push the content back to the original requestor and to the cache, there is still a problem with any other users that come along looking for that content while the caching download is in progress. In this case, the problem has been pushed off to the next user, whose request may timeout while the first user and the cache receive the content, simply because they cannot join the stream already in progress.

The Stream Itself

PartyLine solves this by maintaining a RandomAccessFile and associated FileChannel under the covers. It wraps these in an OutputStream implementation. As new content is written to the OutputStream wrapper, it is pushed to an internal buffer. When the buffer is full, it's pushed to the FileChannel. The total number of bytes written (both to disk and to the buffer) and the number of bytes purged (to disk) are tracked. Meanwhile, other threads in the application can "join" the stream and receive an InputStream implementation. This InputStream pulls chunks of data from the channel into a buffer, being careful never to exceed the purged-byte count in the associated OutputStream. Each time the OutputStream flushes the buffer to disk, it notifies associated InputStreams that there is new content they can buffer and serve to callers.

Example Usage

InputStream trunkIn = // wherever you get your content...
File f = new File("/path/to/my.file.txt");
JoinableOutputStream out = new JoinableOutputStream(f);

CountDownLatch cdl = new CountDownLatch(2);
Runnable r = new Runnable(){
    public void run(){
        try{
            IOUtils.copy( trunkIn, out );
        }catch(IOException e){
            e.printStackTrace();
        }
        cdl.countDown();
    }
};
Thread t = new Thread(r);
t.start();

Runnable r2 = new Runnable(){
    public void run(){
        try{
            System.out.println(
              Thread.currentThread().getName() + ": " + IOUtils.toString(in)
            );
        }catch(IOException e){
            e.printStackTrace();
        }
        cdl.countDown();
    }
};
Thread t2 = new Thread(r2);
t2.start();

// wait for everything to end.
cdl.await();

The File Manager

In addition to joinable streams, it's often useful to have a single manager component that will manage the locks on a given file, and prevent people from performing lower-level operations while something like the joinable output stream is in use.

Example Usage

JoinableFileManager mgr = new JoinableFileManager();

File f = new File("/path/to/my.file.txt");

// Really a JoinableOutputStream
OutputStream out = mgr.openOutputStream(f);

// Really a JoinInputStream related to the above output stream
InputStream in = mgr.openInputStream(f);

// do stuff, or...

//false, you can get an InputStream joined to the current output stream.
boolean readLocked = mgr.isReadLocked(f);

//true, we already have an active output stream
boolean writeLocked = mgr.isWriteLocked(f);

OutputStream out2 = mgr.openOutputStream(f); // waits until 'out' above closes.

// waits for in to close...in this example, infinitely (unless another thread 
// closes 'in')
out.close();

// Success! It was unlocked by the close() operation above.
OutputStream out2 = mgr.openOutputStream(f);

//returns false, because there is already an active stream to that file
mgr.lock(f);

File f2 = new File("/path/to/another.file.txt");
mgr.lock(f2); // return true.

OutputStream out3 = mgr.openOutputStream(f2); // waits until manually unlocked.

mgr.unlock(f2); // Okay, NOW we can open an output stream if we want.
org.commonjava.util

Red Hat NOS

Middleware pipeline content management projects

Versions

Version
2.0
1.16
1.15
1.14
1.13
1.12
1.11
1.10.0
1.9.4
1.9.3
1.9.2
1.9.1
1.9
1.8.1
1.8
1.7.1
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0