org.apache.commons.lang3.concurrent.LazyInitializer Java Examples

The following examples show how to use org.apache.commons.lang3.concurrent.LazyInitializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectHeaderTest.java    From jhdf with MIT License 6 votes vote down vote up
@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);
}
 
Example #2
Source File: SegmentRunner.java    From cassandra-reaper with Apache License 2.0 6 votes vote down vote up
boolean canRepair(
    RepairSegment segment,
    String keyspace,
    JmxProxy coordinator,
    Cluster cluster,
    LazyInitializer<Set<String>> busyHosts) {

  if (RepairSegment.State.NOT_STARTED == segment.getState()) {
    try {
      Map<String, String> dcByNode = getDCsByNodeForRepairSegment(coordinator, cluster, segment, keyspace);

      return !isRepairRunningOnNodes(segment, dcByNode, keyspace, cluster)
          && nodesReadyForNewRepair(coordinator, segment, dcByNode, busyHosts);

    } catch (RuntimeException e) {
      LOG.warn("SegmentRunner couldn't get token ranges from coordinator: ", e);
      String msg = "SegmentRunner couldn't get token ranges from coordinator";
      repairRunner.updateLastEvent(msg);
    }
  }
  return false;
}
 
Example #3
Source File: SegmentRunner.java    From cassandra-reaper with Apache License 2.0 6 votes vote down vote up
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);
    }
  }
}
 
Example #4
Source File: ObjectHeader.java    From jhdf with MIT License 5 votes vote down vote up
public static LazyInitializer<ObjectHeader> lazyReadObjectHeader(HdfFileChannel hdfFc, long address) {
	logger.debug("Creating lazy object header at address: {}", address);
	return new LazyInitializer<ObjectHeader>() {

		@Override
		protected ObjectHeader initialize() {
			logger.debug("Lazy initializing object header at address: {}", address);
			return readObjectHeader(hdfFc, address);
		}

	};
}
 
Example #5
Source File: AbstractNode.java    From jhdf with MIT License 4 votes vote down vote up
public AttributesLazyInitializer(LazyInitializer<ObjectHeader> lazyObjectHeader) {
	this.lazyObjectHeader = lazyObjectHeader;
}