下面列出了怎么用org.apache.commons.lang3.concurrent.ConcurrentException的API类实例代码及写法,或者点击链接到github查看源代码。
private byte[] decompressChunk(Chunk chunk) {
// Get the encoded (i.e. compressed buffer)
final ByteBuffer encodedBuffer = getDataBuffer(chunk);
// Get the encoded data from buffer
final byte[] encodedBytes = new byte[encodedBuffer.remaining()];
encodedBuffer.get(encodedBytes);
try {
final FilterPipeline pipeline = this.lazyPipeline.get();
if (pipeline == null) {
// No filters
logger.debug("No filters returning decoded chunk '{}'", chunk);
return encodedBytes;
}
// Decode using the pipeline applying the filters
final byte[] decodedBytes = pipeline.decode(encodedBytes);
logger.debug("Decoded {}", chunk);
return decodedBytes;
} catch (ConcurrentException e) {
throw new HdfException("Failed to get filter pipeline", e);
}
}
@Test
void testLazyObjectHeader() throws ConcurrentException, IOException {
FileChannel spyFc = Mockito.spy(fc);
HdfFileChannel hdfFileChannel = new HdfFileChannel(spyFc, sb);
LazyInitializer<ObjectHeader> lazyObjectHeader = ObjectHeader.lazyReadObjectHeader(hdfFileChannel, 10904); // int8
// header
// Creating the lazy object header should not touch the file
Mockito.verifyNoInteractions(spyFc);
// Get the actual header should cause the file to be read
lazyObjectHeader.get();
// Check the file was read
verify(spyFc, Mockito.atLeastOnce()).read(any(ByteBuffer.class), anyLong());
// Ensure nothing else was done to the file
Mockito.verifyNoMoreInteractions(spyFc);
}
private void handlePotentialStuckRepairs(LazyInitializer<Set<String>> busyHosts, String hostName)
throws ConcurrentException {
if (!busyHosts.get().contains(hostName) && context.storage instanceof IDistributedStorage) {
try {
JmxProxy hostProxy = clusterFacade.connect(context.storage.getCluster(clusterName), Arrays.asList(hostName));
// We double check that repair is still running there before actually cancelling repairs
if (hostProxy.isRepairRunning()) {
LOG.warn(
"A host ({}) reported that it is involved in a repair, but there is no record "
+ "of any ongoing repair involving the host. Sending command to abort all repairs "
+ "on the host.",
hostName);
hostProxy.cancelAllRepairs();
}
} catch (ReaperException | RuntimeException | JMException e) {
LOG.debug("failed to cancel repairs on host {}", hostName, e);
}
}
}
public static void main(final String[] arguments) {
final BuilderMethods simple1 = new BuilderMethods(1, "The First One");
System.out.println(simple1.getName());
System.out.println(simple1.hashCode());
System.out.println(simple1.toString());
SampleLazyInitializer sampleLazyInitializer = new SampleLazyInitializer();
try {
sampleLazyInitializer.get();
} catch (ConcurrentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
SampleBackgroundInitializer sampleBackgroundInitializer = new SampleBackgroundInitializer();
sampleBackgroundInitializer.start();
// Proceed with other tasks instead of waiting for the SampleBackgroundInitializer task to finish.
try {
Object result = sampleBackgroundInitializer.get();
} catch (ConcurrentException e) {
e.printStackTrace();
}
}
@Override
public Optional<KeyStore> getKeyStore()
{
try
{
return cachedKeyStore.get();
}
catch (ConcurrentException e)
{
throw new IllegalStateException(e);
}
}
@Override
protected Map<ChunkOffset, Chunk> getChunkLookup() {
try {
return chunkLookupLazyInitializer.get();
} catch (ConcurrentException e) {
throw new HdfException("Failed to create chunk lookup for: " + getPath(), e);
}
}
@Override
protected Map<ChunkOffset, Chunk> getChunkLookup() {
try {
return chunkLookupLazyInitializer.get();
} catch (ConcurrentException e) {
throw new HdfException("Failed to create chunk lookup for: " + getPath(), e);
}
}
@Override
protected Map<String, Attribute> initialize() throws ConcurrentException {
logger.debug("Lazy initializing attributes for '{}'", getPath());
final ObjectHeader oh = lazyObjectHeader.get();
List<AttributeMessage> attributeMessages = new ArrayList<>();
if (oh.hasMessageOfType(AttributeInfoMessage.class)) {
// Attributes stored in b-tree
AttributeInfoMessage attributeInfoMessage = oh.getMessageOfType(AttributeInfoMessage.class);
if (attributeInfoMessage.getFractalHeapAddress() != Constants.UNDEFINED_ADDRESS) {
// Create the heap and btree
FractalHeap fractalHeap = new FractalHeap(hdfFc, attributeInfoMessage.getFractalHeapAddress());
BTreeV2<AttributeNameForIndexedAttributesRecord> btree = new BTreeV2<>(hdfFc,
attributeInfoMessage.getAttributeNameBTreeAddress());
// Read the attribute messages from the btree+heap
for (AttributeNameForIndexedAttributesRecord attributeRecord : btree.getRecords()) {
ByteBuffer bb = fractalHeap.getId(attributeRecord.getHeapId());
AttributeMessage attributeMessage = new AttributeMessage(bb, hdfFc.getSuperblock(),
attributeRecord.getFlags());
logger.trace("Read attribute message '{}'", attributeMessage);
attributeMessages.add(attributeMessage);
}
}
}
// Add the messages stored directly in the header
attributeMessages.addAll(oh.getMessagesOfType(AttributeMessage.class));
return attributeMessages.stream()
.collect(
toMap(AttributeMessage::getName,
message -> new AttributeImpl(hdfFc, AbstractNode.this, message)));
}
@Override
protected Map<String, Node> initialize() throws ConcurrentException {
logger.info("Lazy loading children of '{}'", getPath());
if (header.get().hasMessageOfType(SymbolTableMessage.class)) {
// Its an old style Group
return createOldStyleGroup(header.get());
} else {
return createNewStyleGroup(header.get());
}
}
public static BasicMetaDataImpl getInstance() {
try {
return initializer.get();
} catch (ConcurrentException e) {
throw new NetSuiteException("Initialization error", e);
}
}
public static BasicMetaDataImpl getInstance() {
try {
return initializer.get();
} catch (ConcurrentException e) {
throw new NetSuiteException("Initialization error", e);
}
}
public static BasicMetaDataImpl getInstance() {
try {
return initializer.get();
} catch (ConcurrentException e) {
throw new NetSuiteException("Initialization error", e);
}
}
public static BasicMetaDataImpl getInstance() {
try {
return initializer.get();
} catch (ConcurrentException e) {
throw new NetSuiteException("Initialization error", e);
}
}
@Test
public void ConcurrentExceptionSample() throws ConcurrentException {
final Error err = new AssertionError("Test");
try {
ConcurrentUtils.handleCause(new ExecutionException(err));
fail("Error not thrown!");
} catch (final Error e) {
assertEquals("Wrong error", err, e);
}
}
@Override protected BasicMetaDataImpl initialize() throws ConcurrentException {
return new BasicMetaDataImpl();
}
@Override protected BasicMetaDataImpl initialize() throws ConcurrentException {
return new BasicMetaDataImpl();
}
@Override protected BasicMetaDataImpl initialize() throws ConcurrentException {
return new BasicMetaDataImpl();
}
@Override protected BasicMetaDataImpl initialize() throws ConcurrentException {
return new BasicMetaDataImpl();
}
@Test
public void givenLazyInitializerInstance_whenCalledget_thenCorrect() throws ConcurrentException {
UserInitializer userInitializer = new UserInitializer();
assertThat(userInitializer.get()).isInstanceOf(User.class);
}