
org.objectfabric.ThreadContext Maven / Gradle / Ivy
The newest version!
/**
* This file is part of ObjectFabric (http://objectfabric.org).
*
* ObjectFabric is licensed under the Apache License, Version 2.0, the terms
* of which may be found at http://www.apache.org/licenses/LICENSE-2.0.html.
*
* Copyright ObjectFabric Inc.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.objectfabric;
import java.lang.ref.WeakReference;
import java.util.Iterator;
@SuppressWarnings({ "rawtypes", "unchecked" })
final class ThreadContext extends PlatformThreadContext {
private static final PlatformConcurrentMap _instances = new PlatformConcurrentMap();
final byte[] Sha1 = new byte[SHA1Digest.LENGTH];
final char[] PathCache = new char[Utils.TIME_HEX + Utils.PEER_HEX];
List Buffs;
private final Reader _reader = new Reader();
byte[] Buffer;
static ThreadContext get() {
ThreadContext value = (ThreadContext) getInstance();
if (value == null) {
Object key;
if (Debug.THREADS)
ThreadAssert.suspend(key = new Object());
setInstance(value = new ThreadContext());
WeakReference ref = new WeakReference(value);
_instances.put(ref, ref);
if (Debug.THREADS) {
ThreadAssert.suspend(value);
ThreadAssert.resume(key);
}
}
return value;
}
private ThreadContext() {
}
final Reader getReader() {
return _reader;
}
static final Iterable getInstances() {
return new Iterable() {
@Override
public Iterator iterator() {
return new It(_instances.keySet().iterator());
}
};
}
static void disposeAll() {
if (Debug.THREADS)
for (ThreadContext context : getInstances())
context.dispose();
}
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy