org.apache.shindig.protocol.conversion.xstream
Class ThreadSafeWriterStack

java.lang.Object
  extended by org.apache.shindig.protocol.conversion.xstream.ThreadSafeWriterStack
All Implemented Interfaces:
WriterStack

public class ThreadSafeWriterStack
extends Object
implements WriterStack

A simple implementation of a WriterStack that can be shared amongst multiple threads and will record the state of each thread. This cannot however be shared amongst multiple writers on multiple threads as this would lead to an inconsistent state. In the shindig implementation this is not an issue as the serialization process is atomic below the API.


Constructor Summary
ThreadSafeWriterStack()
          Create a WriterStack that is thread safe.
 
Method Summary
 String peek()
          Peek into the current location of the writer.
 Object peek(int i)
          Look at the node name on the top of the stack on the current thread.
 NamespaceSet peekNamespace()
          
 String pop()
          Remove a node name from the stack on the current thread.
 void push(String name, NamespaceSet namespaceSet)
          Add an element name to the stack on the current thread.
 void reset()
          Reset the stack back to the default state.
 int size()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadSafeWriterStack

public ThreadSafeWriterStack()
Create a WriterStack that is thread safe. The stack will store its contents on the thread so this class can be shared amongst multiple threads, but obviously there must be only one instance of the class per writer per thread.

Method Detail

push

public void push(String name,
                 NamespaceSet namespaceSet)
Add an element name to the stack on the current thread.

Specified by:
push in interface WriterStack
Parameters:
name - the node name just added.
namespaceSet - the namespace set associated with the current element.

pop

public String pop()
Remove a node name from the stack on the current thread.

Specified by:
pop in interface WriterStack
Returns:
the node name just ended.

peek

public String peek()
Peek into the current location of the writer.

Specified by:
peek in interface WriterStack
Returns:
the name of the current node.
See Also:
WriterStack.peek()

peekNamespace

public NamespaceSet peekNamespace()

Specified by:
peekNamespace in interface WriterStack
Returns:
the current namespace.
See Also:
WriterStack.peekNamespace()

peek

public Object peek(int i)
Look at the node name on the top of the stack on the current thread.

Returns:
the current node name.

reset

public void reset()
Reset the stack back to the default state.

Specified by:
reset in interface WriterStack
See Also:
WriterStack.reset()

size

public int size()

Specified by:
size in interface WriterStack
Returns:
the size of the statck
See Also:
WriterStack.size()


Copyright © 2007-2012. All Rights Reserved.