Java Code Examples for java.util.concurrent.locks.ReentrantReadWriteLock#readLock()

The following examples show how to use java.util.concurrent.locks.ReentrantReadWriteLock#readLock() . 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: RMNodeImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
public RMNodeImpl(NodeId nodeId, RMContext context, String hostName,
    int cmPort, int httpPort, Node node, Resource capability, String nodeManagerVersion) {
  this.nodeId = nodeId;
  this.context = context;
  this.hostName = hostName;
  this.commandPort = cmPort;
  this.httpPort = httpPort;
  this.totalCapability = capability; 
  this.nodeAddress = hostName + ":" + cmPort;
  this.httpAddress = hostName + ":" + httpPort;
  this.node = node;
  this.healthReport = "Healthy";
  this.lastHealthReportTime = System.currentTimeMillis();
  this.nodeManagerVersion = nodeManagerVersion;

  this.latestNodeHeartBeatResponse.setResponseId(0);

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);
  
  this.nodeUpdateQueue = new ConcurrentLinkedQueue<UpdatedContainerInfo>();  
}
 
Example 2
Source File: AbstractTagCacheObject.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The clone is provided with <b>new</b> locks: these do not lock access
 * to the object residing in the cache (the clone is no longer in the
 * cache).
 */
@Override
public Object clone() throws CloneNotSupportedException {
  AbstractTagCacheObject cacheObject = (AbstractTagCacheObject) super.clone();
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  cacheObject.readLock = lock.readLock();
  cacheObject.writeLock = lock.writeLock();
  if (dataTagQuality != null) {
    cacheObject.dataTagQuality = (DataTagQuality) dataTagQuality.clone();
  }
  cacheObject.alarmIds = (ArrayList<Long>) ((ArrayList<Long>) alarmIds).clone();
  cacheObject.ruleIds = (ArrayList<Long>) ((ArrayList<Long>) ruleIds).clone();
  if (cacheTimestamp != null) {
    cacheObject.cacheTimestamp = (Timestamp) cacheTimestamp.clone();
  }
  return cacheObject;
}
 
Example 3
Source File: FifoCache.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param maxSize
 *            the maximum number of entries of the cache
 */
public FifoCache(final int maxSize) {
    if (maxSize < 1) {
        throw new IllegalArgumentException("maxSize " + maxSize
                                           + " must be at least 1");
    }
    map = new BoundedLinkedHashMap<>(maxSize);
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    rlock = lock.readLock();
    wlock = lock.writeLock();
}
 
Example 4
Source File: RMStateStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public RMStateStore() {
  super(RMStateStore.class.getName());
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();
  stateMachine = stateMachineFactory.make(this);
}
 
Example 5
Source File: ApplicationImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public ApplicationImpl(Dispatcher dispatcher, String user, ApplicationId appId,
    Credentials credentials, Context context) {
  this.dispatcher = dispatcher;
  this.user = user;
  this.appId = appId;
  this.credentials = credentials;
  this.aclsManager = context.getApplicationACLsManager();
  this.context = context;
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  readLock = lock.readLock();
  writeLock = lock.writeLock();
  stateMachine = stateMachineFactory.make(this);
}
 
Example 6
Source File: FileArchiverNotifierImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
public FileArchiverNotifierImpl(
    Connection conn, Configuration conf, FileSystem fs, TableName tn) {
  this.conn = conn;
  this.conf = conf;
  this.fs = fs;
  this.tn = tn;
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  readLock = lock.readLock();
  writeLock = lock.writeLock();
}
 
Example 7
Source File: AbstractDataSourceHandler.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public AbstractDataSourceHandler ( final ObjectPoolTracker<DataSource> poolTracker )
{
    this.poolTracker = poolTracker;
    this.serviceListener = new ServiceListener () {

        @Override
        public void dataSourceChanged ( final DataSource dataSource )
        {
            AbstractDataSourceHandler.this.setDataSource ( dataSource );
        }
    };

    this.dataSourceListener = new DataSourceListener () {

        @Override
        public void stateChanged ( final DataItemValue value )
        {
            AbstractDataSourceHandler.this.stateChanged ( value );
        }
    };

    final ReentrantReadWriteLock lock = new ReentrantReadWriteLock ();
    this.dataSourceReadLock = lock.readLock ();
    this.dataSourceWriteLock = lock.writeLock ();

    this.trackerLock = new ReentrantLock ();
}
 
Example 8
Source File: ValueProtectingMap.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Construct providing a protected map, complementing the set of
 * {@link #DEFAULT_IMMUTABLE_CLASSES default immutable classes}
 * 
 * @param protectedMap          the map to safeguard
 * @param immutableClasses      additional immutable classes
 *                              over and above the {@link #DEFAULT_IMMUTABLE_CLASSES default set}
 *                              (may be <tt>null</tt>
 */
public ValueProtectingMap(Map<K, V> protectedMap, Set<Class<?>> immutableClasses)
{
    // Unwrap any internal maps if given a value protecting map
    if (protectedMap instanceof ValueProtectingMap)
    {
        ValueProtectingMap<K, V> mapTemp = (ValueProtectingMap<K, V>) protectedMap;
        this.map = mapTemp.map;
    }
    else
    {
        this.map = protectedMap;
    }
    
    this.cloned = false;
    if (immutableClasses == null)
    {
        this.immutableClasses = Collections.emptySet();
    }
    else
    {
        this.immutableClasses = new HashSet<Class<?>>(immutableClasses);
    }
    // Construct locks
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    this.readLock = lock.readLock();
    this.writeLock = lock.writeLock();
}
 
Example 9
Source File: AbstractYarnScheduler.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Construct the service.
 *
 * @param name service name
 */
public AbstractYarnScheduler(String name) {
  super(name);
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.maxAllocReadLock = lock.readLock();
  this.maxAllocWriteLock = lock.writeLock();
}
 
Example 10
Source File: PathMapper.java    From alfresco-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Default constructor
 */
public PathMapper()
{
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    readLock = lock.readLock();
    writeLock = lock.writeLock();
    
    pathMaps = new HashMap<String, Set<String>>(37);
    derivedPathMaps = new HashMap<String, Set<String>>(127);
    derivedPathMapsPartial = new HashMap<String, Set<String>>(127);
}
 
Example 11
Source File: ResourceUsage.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public ResourceUsage() {
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  readLock = lock.readLock();
  writeLock = lock.writeLock();

  usages = new HashMap<String, UsageByLabel>();
  usages.put(NL, new UsageByLabel(NL));
}
 
Example 12
Source File: DefaultEventbus.java    From moleculer-java with MIT License 5 votes vote down vote up
public DefaultEventbus(boolean asyncLocalInvocation) {

		// Async or direct local invocation
		this.asyncLocalInvocation = asyncLocalInvocation;

		// Init locks
		ReentrantReadWriteLock registryLock = new ReentrantReadWriteLock(true);
		registryReadLock = registryLock.readLock();
		registryWriteLock = registryLock.writeLock();

		ReentrantReadWriteLock requestStreamLock = new ReentrantReadWriteLock(false);
		requestStreamReadLock = requestStreamLock.readLock();
		requestStreamWriteLock = requestStreamLock.writeLock();
	}
 
Example 13
Source File: RMContainerImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
public RMContainerImpl(Container container,
    ApplicationAttemptId appAttemptId, NodeId nodeId,
    String user, RMContext rmContext, long creationTime) {
  this.stateMachine = stateMachineFactory.make(this);
  this.containerId = container.getId();
  this.nodeId = nodeId;
  this.container = container;
  this.appAttemptId = appAttemptId;
  this.user = user;
  this.creationTime = creationTime;
  this.rmContext = rmContext;
  this.eventHandler = rmContext.getDispatcher().getEventHandler();
  this.containerAllocationExpirer = rmContext.getContainerAllocationExpirer();
  this.isAMContainer = false;
  this.resourceRequests  = null;
  this.resumeOpportunity = 0;
  
  this.utilization = 1;
  this.suspendTime = new LinkedList<Long>();
  this.resumeTime  = new LinkedList<Long>();

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();
  
  this.PR_NUMBER=rmContext.getYarnConfiguration().getInt(
  		"yarn.resourcemanager.monitor.capacity.preemption.pr_number", 2);
  		

  rmContext.getRMApplicationHistoryWriter().containerStarted(this);
  rmContext.getSystemMetricsPublisher().containerCreated(
      this, this.creationTime);
}
 
Example 14
Source File: AbstractYarnScheduler.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Construct the service.
 *
 * @param name service name
 */
public AbstractYarnScheduler(String name) {
  super(name);
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.maxAllocReadLock = lock.readLock();
  this.maxAllocWriteLock = lock.writeLock();
}
 
Example 15
Source File: TaskAttemptImpl.java    From tez with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public TaskAttemptImpl(TezTaskAttemptID attemptId, EventHandler eventHandler,
    TaskCommunicatorManagerInterface taskCommunicatorManagerInterface, Configuration conf, Clock clock,
    TaskHeartbeatHandler taskHeartbeatHandler, AppContext appContext,
    boolean isRescheduled,
    Resource resource, ContainerContext containerContext, boolean leafVertex,
    Task task, TaskLocationHint locationHint, TaskSpec taskSpec,
    TezTaskAttemptID schedulingCausalTA) {

  ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
  this.readLock = rwLock.readLock();
  this.writeLock = rwLock.writeLock();
  this.attemptId = attemptId;
  this.eventHandler = eventHandler;
  //Reported status
  this.conf = conf;
  this.clock = clock;
  this.taskHeartbeatHandler = taskHeartbeatHandler;
  this.appContext = appContext;
  this.vertex = task.getVertex();
  this.task = task;
  this.locationHint = locationHint;
  this.taskSpec = taskSpec;
  this.creationCausalTA = schedulingCausalTA;
  this.creationTime = clock.getTime();

  this.reportedStatus = new TaskAttemptStatus(this.attemptId);
  initTaskAttemptStatus(reportedStatus);
  RackResolver.init(conf);
  this.stateMachine = stateMachineFactory.make(this);
  this.isRescheduled = isRescheduled;
  this.taskResource = resource;
  this.containerContext = containerContext;
  this.leafVertex = leafVertex;
  this.hungIntervalMax = conf.getLong(
      TezConfiguration.TEZ_TASK_PROGRESS_STUCK_INTERVAL_MS, 
      TezConfiguration.TEZ_TASK_PROGRESS_STUCK_INTERVAL_MS_DEFAULT);

  this.recoveryData = appContext.getDAGRecoveryData() == null ?
      null : appContext.getDAGRecoveryData().getTaskAttemptRecoveryData(attemptId);
}
 
Example 16
Source File: RealtimeInvertedIndexReader.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public RealtimeInvertedIndexReader() {
  ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  _readLock = readWriteLock.readLock();
  _writeLock = readWriteLock.writeLock();
}
 
Example 17
Source File: UnAckedMessageTracker.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public UnAckedMessageTracker(PulsarClientImpl client, ConsumerBase<?> consumerBase, long ackTimeoutMillis, long tickDurationInMs) {
    Preconditions.checkArgument(tickDurationInMs > 0 && ackTimeoutMillis >= tickDurationInMs);
    this.ackTimeoutMillis = ackTimeoutMillis;
    this.tickDurationInMs = tickDurationInMs;
    ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
    this.readLock = readWriteLock.readLock();
    this.writeLock = readWriteLock.writeLock();
    this.messageIdPartitionMap = new ConcurrentHashMap<>();
    this.timePartitions = new ArrayDeque<>();

    int blankPartitions = (int)Math.ceil((double)this.ackTimeoutMillis / this.tickDurationInMs);
    for (int i = 0; i < blankPartitions + 1; i++) {
        timePartitions.add(new ConcurrentOpenHashSet<>(16, 1));
    }

    timeout = client.timer().newTimeout(new TimerTask() {
        @Override
        public void run(Timeout t) throws Exception {
            Set<MessageId> messageIds = TL_MESSAGE_IDS_SET.get();
            messageIds.clear();

            writeLock.lock();
            try {
                ConcurrentOpenHashSet<MessageId> headPartition = timePartitions.removeFirst();
                if (!headPartition.isEmpty()) {
                    log.warn("[{}] {} messages have timed-out", consumerBase, headPartition.size());
                    headPartition.forEach(messageId -> {
                        addChunkedMessageIdsAndRemoveFromSequnceMap(messageId, messageIds, consumerBase);
                        messageIds.add(messageId);
                        messageIdPartitionMap.remove(messageId);
                    });
                }

                headPartition.clear();
                timePartitions.addLast(headPartition);
            } finally {
                if (messageIds.size() > 0) {
                    consumerBase.onAckTimeoutSend(messageIds);
                    consumerBase.redeliverUnacknowledgedMessages(messageIds);
                }
                timeout = client.timer().newTimeout(this, tickDurationInMs, TimeUnit.MILLISECONDS);
                writeLock.unlock();
            }
        }
    }, this.tickDurationInMs, TimeUnit.MILLISECONDS);
}
 
Example 18
Source File: SocketWrapper.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public SocketWrapper(E socket) {
    this.socket = socket;
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    this.blockingStatusReadLock = lock.readLock();
    this.blockingStatusWriteLock =lock.writeLock();
}
 
Example 19
Source File: RMAppImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
public RMAppImpl(ApplicationId applicationId, RMContext rmContext,
    Configuration config, String name, String user, String queue,
    ApplicationSubmissionContext submissionContext, YarnScheduler scheduler,
    ApplicationMasterService masterService, long submitTime,
    String applicationType, Set<String> applicationTags, 
    ResourceRequest amReq) {

  this.systemClock = new SystemClock();

  this.applicationId = applicationId;
  this.name = name;
  this.rmContext = rmContext;
  this.dispatcher = rmContext.getDispatcher();
  this.handler = dispatcher.getEventHandler();
  this.conf = config;
  this.user = user;
  this.queue = queue;
  this.submissionContext = submissionContext;
  this.scheduler = scheduler;
  this.masterService = masterService;
  this.submitTime = submitTime;
  this.startTime = this.systemClock.getTime();
  this.applicationType = applicationType;
  this.applicationTags = applicationTags;
  this.amReq = amReq;

  int globalMaxAppAttempts = conf.getInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS,
      YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS);
  int individualMaxAppAttempts = submissionContext.getMaxAppAttempts();
  if (individualMaxAppAttempts <= 0 ||
      individualMaxAppAttempts > globalMaxAppAttempts) {
    this.maxAppAttempts = globalMaxAppAttempts;
    LOG.warn("The specific max attempts: " + individualMaxAppAttempts
        + " for application: " + applicationId.getId()
        + " is invalid, because it is out of the range [1, "
        + globalMaxAppAttempts + "]. Use the global max attempts instead.");
  } else {
    this.maxAppAttempts = individualMaxAppAttempts;
  }

  this.attemptFailuresValidityInterval =
      submissionContext.getAttemptFailuresValidityInterval();
  if (this.attemptFailuresValidityInterval > 0) {
    LOG.info("The attemptFailuresValidityInterval for the application: "
        + this.applicationId + " is " + this.attemptFailuresValidityInterval
        + ".");
  }

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);

  rmContext.getRMApplicationHistoryWriter().applicationStarted(this);
  rmContext.getSystemMetricsPublisher().appCreated(this, startTime);
}
 
Example 20
Source File: RMAppImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public RMAppImpl(ApplicationId applicationId, RMContext rmContext,
    Configuration config, String name, String user, String queue,
    ApplicationSubmissionContext submissionContext, YarnScheduler scheduler,
    ApplicationMasterService masterService, long submitTime,
    String applicationType, Set<String> applicationTags, 
    ResourceRequest amReq) {

  this.systemClock = new SystemClock();

  this.applicationId = applicationId;
  this.name = name;
  this.rmContext = rmContext;
  this.dispatcher = rmContext.getDispatcher();
  this.handler = dispatcher.getEventHandler();
  this.conf = config;
  this.user = user;
  this.queue = queue;
  this.submissionContext = submissionContext;
  this.scheduler = scheduler;
  this.masterService = masterService;
  this.submitTime = submitTime;
  this.startTime = this.systemClock.getTime();
  this.applicationType = applicationType;
  this.applicationTags = applicationTags;
  this.amReq = amReq;

  int globalMaxAppAttempts = conf.getInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS,
      YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS);
  int individualMaxAppAttempts = submissionContext.getMaxAppAttempts();
  if (individualMaxAppAttempts <= 0 ||
      individualMaxAppAttempts > globalMaxAppAttempts) {
    this.maxAppAttempts = globalMaxAppAttempts;
    LOG.warn("The specific max attempts: " + individualMaxAppAttempts
        + " for application: " + applicationId.getId()
        + " is invalid, because it is out of the range [1, "
        + globalMaxAppAttempts + "]. Use the global max attempts instead.");
  } else {
    this.maxAppAttempts = individualMaxAppAttempts;
  }

  this.attemptFailuresValidityInterval =
      submissionContext.getAttemptFailuresValidityInterval();
  if (this.attemptFailuresValidityInterval > 0) {
    LOG.info("The attemptFailuresValidityInterval for the application: "
        + this.applicationId + " is " + this.attemptFailuresValidityInterval
        + ".");
  }

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);

  rmContext.getRMApplicationHistoryWriter().applicationStarted(this);
  rmContext.getSystemMetricsPublisher().appCreated(this, startTime);
}