java.util.concurrent.locks.ReadWriteLock#readLock()源码实例Demo

下面列出了java.util.concurrent.locks.ReadWriteLock#readLock() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jstarcraft-core   文件: LuceneEngine.java
public LuceneEngine(IndexWriterConfig config, Path path) {
    try {
        this.config = config;
        Directory transienceDirectory = new ByteBuffersDirectory();
        this.transienceManager = new TransienceManager((IndexWriterConfig) BeanUtils.cloneBean(config), transienceDirectory);
        Directory persistenceDirectory = FSDirectory.open(path);
        this.persistenceManager = new PersistenceManager((IndexWriterConfig) BeanUtils.cloneBean(config), persistenceDirectory);
        this.searcher = new LuceneSearcher(this.transienceManager, this.persistenceManager);

        this.semaphore = new AtomicInteger();
        ReadWriteLock lock = new ReentrantReadWriteLock();
        this.readLock = lock.readLock();
        this.writeLock = lock.writeLock();
    } catch (Exception exception) {
        throw new StorageException(exception);
    }
}
 
源代码2 项目: Elasticsearch   文件: LocalTranslog.java
public LocalTranslog(TranslogConfig config) throws IOException {
    super(config.getShardId(), config.getIndexSettings());
    ReadWriteLock rwl = new ReentrantReadWriteLock();
    readLock = new ReleasableLock(rwl.readLock());
    writeLock = new ReleasableLock(rwl.writeLock());
    this.translogPath = config.getTranslogPath();
    // clean all files
    Files.createDirectories(this.translogPath);
    Files.walkFileTree(this.translogPath, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file,
                BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }
    });
    
    // create a new directory
    writeChannel = FileChannel.open(this.translogPath.resolve(getFileNameFromId(tmpTranslogGeneration.get())), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
    writtenOffset = 0;
}
 
源代码3 项目: Elasticsearch   文件: Translog.java
public Translog(TranslogConfig config, String nodeId) {
    super(config.getShardId(), config.getIndexSettings());
    this.config = null;
    recoveredTranslogs = null;
    syncScheduler = null;
    bigArrays = null;
    ReadWriteLock rwl = new ReentrantReadWriteLock();
    readLock = new ReleasableLock(rwl.readLock());
    writeLock = new ReleasableLock(rwl.writeLock());
    location = null;
    current = null;
    currentCommittingTranslog = null;
    lastCommittedTranslogFileGeneration = -1; 
    config = null;
    translogUUID = null;
}
 
源代码4 项目: hadoop   文件: ContainerImpl.java
public ContainerImpl(Configuration conf, Dispatcher dispatcher,
    NMStateStoreService stateStore, ContainerLaunchContext launchContext,
    Credentials creds, NodeManagerMetrics metrics,
    ContainerTokenIdentifier containerTokenIdentifier) {
  this.daemonConf = conf;
  this.dispatcher = dispatcher;
  this.stateStore = stateStore;
  this.launchContext = launchContext;
  this.containerTokenIdentifier = containerTokenIdentifier;
  this.containerId = containerTokenIdentifier.getContainerID();
  this.resource = containerTokenIdentifier.getResource();
  this.diagnostics = new StringBuilder();
  this.credentials = creds;
  this.metrics = metrics;
  user = containerTokenIdentifier.getApplicationSubmitter();
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  this.readLock = readWriteLock.readLock();
  this.writeLock = readWriteLock.writeLock();

  stateMachine = stateMachineFactory.make(this);
}
 
源代码5 项目: Flink-CEPplus   文件: BlobServerConnection.java
/**
 * Creates a new BLOB connection for a client request.
 *
 * @param clientSocket The socket to read/write data.
 * @param blobServer The BLOB server.
 */
BlobServerConnection(Socket clientSocket, BlobServer blobServer) {
	super("BLOB connection for " + clientSocket.getRemoteSocketAddress());
	setDaemon(true);

	this.clientSocket = clientSocket;
	this.blobServer = checkNotNull(blobServer);

	ReadWriteLock readWriteLock = blobServer.getReadWriteLock();

	this.readLock = readWriteLock.readLock();
}
 
源代码6 项目: flink   文件: BlobServerConnection.java
/**
 * Creates a new BLOB connection for a client request.
 *
 * @param clientSocket The socket to read/write data.
 * @param blobServer The BLOB server.
 */
BlobServerConnection(Socket clientSocket, BlobServer blobServer) {
	super("BLOB connection for " + clientSocket.getRemoteSocketAddress());
	setDaemon(true);

	this.clientSocket = clientSocket;
	this.blobServer = checkNotNull(blobServer);

	ReadWriteLock readWriteLock = blobServer.getReadWriteLock();

	this.readLock = readWriteLock.readLock();
}
 
源代码7 项目: dorado   文件: SimpleLRUCache.java
private SimpleLRUCache(int capacity) {
	this.cache = new LRUMap<K, V>(capacity);
	ReadWriteLock lock = new ReentrantReadWriteLock();

	this.r = lock.readLock();
	this.w = lock.writeLock();
}
 
源代码8 项目: neoscada   文件: ConfigurationFactoryImpl.java
public ConfigurationFactoryImpl ()
{
    final ReadWriteLock lock = new ReentrantReadWriteLock ();
    this.readLock = lock.readLock ();
    this.writeLock = lock.writeLock ();

    final BundleContext context = FrameworkUtil.getBundle ( DataContext.class ).getBundleContext ();

    this.executor = new ScheduledExportedExecutorService ( "org.eclipse.scada.da.server.exporter.rest", 1 );
    this.hiveSource = new ServiceListenerHiveSource ( context, this.executor );
    this.hiveSource.open ();
}
 
源代码9 项目: lams   文件: NaturalIdStatisticsImpl.java
NaturalIdStatisticsImpl(EntityPersister rootEntityDescriptor) {
	super(
			() -> rootEntityDescriptor.getNaturalIdCacheAccessStrategy() != null
					? rootEntityDescriptor.getNaturalIdCacheAccessStrategy().getRegion()
					: null
	);
	this.rootEntityName = rootEntityDescriptor.getRootEntityName();
	final ReadWriteLock lock = new ReentrantReadWriteLock();
	this.readLock = lock.readLock();
	this.writeLock = lock.writeLock();
}
 
DeprecatedNaturalIdCacheStatisticsImpl(String regionName, Set<NaturalIdDataAccess> accessStrategies) {
	this.regionName = regionName;
	this.accessStrategies = accessStrategies;
	final ReadWriteLock lock = new ReentrantReadWriteLock();
	this.readLock = lock.readLock();
	this.writeLock = lock.writeLock();
}
 
源代码11 项目: azeroth   文件: MemoryTokenStore.java
public MemoryTokenStore() {
    this.cache = CacheBuilder.newBuilder().softValues().expireAfterAccess(120, TimeUnit.SECONDS)
            .build();
    ReadWriteLock lock = new ReentrantReadWriteLock();
    this.r = lock.readLock();
    this.w = lock.writeLock();
}
 
源代码12 项目: hadoop   文件: LocalizedResource.java
public LocalizedResource(LocalResourceRequest rsrc, Dispatcher dispatcher) {
  this.rsrc = rsrc;
  this.dispatcher = dispatcher;
  this.ref = new LinkedList<ContainerId>();

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  this.readLock = readWriteLock.readLock();
  this.writeLock = readWriteLock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);
}
 
源代码13 项目: hadoop   文件: TaskImpl.java
public TaskImpl(JobId jobId, TaskType taskType, int partition,
    EventHandler eventHandler, Path remoteJobConfFile, JobConf conf,
    TaskAttemptListener taskAttemptListener,
    Token<JobTokenIdentifier> jobToken,
    Credentials credentials, Clock clock,
    int appAttemptId, MRAppMetrics metrics, AppContext appContext) {
  this.conf = conf;
  this.clock = clock;
  this.jobFile = remoteJobConfFile;
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = readWriteLock.readLock();
  writeLock = readWriteLock.writeLock();
  this.attempts = Collections.emptyMap();
  this.finishedAttempts = new HashSet<TaskAttemptId>(2);
  this.failedAttempts = new HashSet<TaskAttemptId>(2);
  this.inProgressAttempts = new HashSet<TaskAttemptId>(2);
  // This overridable method call is okay in a constructor because we
  //  have a convention that none of the overrides depends on any
  //  fields that need initialization.
  maxAttempts = getMaxAttempts();
  taskId = MRBuilderUtils.newTaskId(jobId, partition, taskType);
  this.partition = partition;
  this.taskAttemptListener = taskAttemptListener;
  this.eventHandler = eventHandler;
  this.credentials = credentials;
  this.jobToken = jobToken;
  this.metrics = metrics;
  this.appContext = appContext;
  this.encryptedShuffle = conf.getBoolean(MRConfig.SHUFFLE_SSL_ENABLED_KEY,
                                          MRConfig.SHUFFLE_SSL_ENABLED_DEFAULT);

  // This "this leak" is okay because the retained pointer is in an
  //  instance variable.
  stateMachine = stateMachineFactory.make(this);

  // All the new TaskAttemptIDs are generated based on MR
  // ApplicationAttemptID so that attempts from previous lives don't
  // over-step the current one. This assumes that a task won't have more
  // than 1000 attempts in its single generation, which is very reasonable.
  nextAttemptNumber = (appAttemptId - 1) * 1000;
}
 
源代码14 项目: joyrpc   文件: Switcher.java
public Switcher(final ReadWriteLock lock) {
    this(lock.readLock(), lock.writeLock(), new AtomicBoolean());
}
 
/**
 * Default constructor 
 */
public AggregatingContentStore()
{
    ReadWriteLock storeLock = new ReentrantReadWriteLock();
    readLock = storeLock.readLock();
}
 
源代码16 项目: hadoop   文件: JobImpl.java
public JobImpl(JobId jobId, ApplicationAttemptId applicationAttemptId,
    Configuration conf, EventHandler eventHandler,
    TaskAttemptListener taskAttemptListener,
    JobTokenSecretManager jobTokenSecretManager,
    Credentials jobCredentials, Clock clock,
    Map<TaskId, TaskInfo> completedTasksFromPreviousRun, MRAppMetrics metrics,
    OutputCommitter committer, boolean newApiCommitter, String userName,
    long appSubmitTime, List<AMInfo> amInfos, AppContext appContext,
    JobStateInternal forcedState, String forcedDiagnostic) {
  this.applicationAttemptId = applicationAttemptId;
  this.jobId = jobId;
  this.jobName = conf.get(JobContext.JOB_NAME, "<missing job name>");
  this.conf = new JobConf(conf);
  this.metrics = metrics;
  this.clock = clock;
  this.completedTasksFromPreviousRun = completedTasksFromPreviousRun;
  this.amInfos = amInfos;
  this.appContext = appContext;
  this.userName = userName;
  this.queueName = conf.get(MRJobConfig.QUEUE_NAME, "default");
  this.appSubmitTime = appSubmitTime;
  this.oldJobId = TypeConverter.fromYarn(jobId);
  this.committer = committer;
  this.newApiCommitter = newApiCommitter;

  this.taskAttemptListener = taskAttemptListener;
  this.eventHandler = eventHandler;
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  this.readLock = readWriteLock.readLock();
  this.writeLock = readWriteLock.writeLock();

  this.jobCredentials = jobCredentials;
  this.jobTokenSecretManager = jobTokenSecretManager;

  this.aclsManager = new JobACLsManager(conf);
  this.username = System.getProperty("user.name");
  this.jobACLs = aclsManager.constructJobACLs(conf);

  ThreadFactory threadFactory = new ThreadFactoryBuilder()
    .setNameFormat("Job Fail Wait Timeout Monitor #%d")
    .setDaemon(true)
    .build();
  this.executor = new ScheduledThreadPoolExecutor(1, threadFactory);

  // This "this leak" is okay because the retained pointer is in an
  //  instance variable.
  stateMachine = stateMachineFactory.make(this);
  this.forcedState  = forcedState;
  if(forcedDiagnostic != null) {
    this.diagnostics.add(forcedDiagnostic);
  }
  
  this.maxAllowedFetchFailuresFraction = conf.getFloat(
      MRJobConfig.MAX_ALLOWED_FETCH_FAILURES_FRACTION,
      MRJobConfig.DEFAULT_MAX_ALLOWED_FETCH_FAILURES_FRACTION);
  this.maxFetchFailuresNotifications = conf.getInt(
      MRJobConfig.MAX_FETCH_FAILURES_NOTIFICATIONS,
      MRJobConfig.DEFAULT_MAX_FETCH_FAILURES_NOTIFICATIONS);
}
 
源代码17 项目: neoscada   文件: AuthenticationServiceImpl.java
public AuthenticationServiceImpl ()
{
    final ReadWriteLock lock = new ReentrantReadWriteLock ();
    this.readLock = lock.readLock ();
    this.writeLock = lock.writeLock ();
}
 
源代码18 项目: lams   文件: QueryStatisticsImpl.java
QueryStatisticsImpl(String query) {
	this.query = query;
	ReadWriteLock lock = new ReentrantReadWriteLock();
	this.readLock = lock.readLock();
	this.writeLock = lock.writeLock();
}
 
源代码19 项目: hadoop   文件: TaskAttemptImpl.java
public TaskAttemptImpl(TaskId taskId, int i, 
    EventHandler eventHandler,
    TaskAttemptListener taskAttemptListener, Path jobFile, int partition,
    JobConf conf, String[] dataLocalHosts,
    Token<JobTokenIdentifier> jobToken,
    Credentials credentials, Clock clock,
    AppContext appContext) {
  oldJobId = TypeConverter.fromYarn(taskId.getJobId());
  this.conf = conf;
  this.clock = clock;
  attemptId = recordFactory.newRecordInstance(TaskAttemptId.class);
  attemptId.setTaskId(taskId);
  attemptId.setId(i);
  this.taskAttemptListener = taskAttemptListener;
  this.appContext = appContext;

  // Initialize reportedStatus
  reportedStatus = new TaskAttemptStatus();
  initTaskAttemptStatus(reportedStatus);

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = readWriteLock.readLock();
  writeLock = readWriteLock.writeLock();

  this.credentials = credentials;
  this.jobToken = jobToken;
  this.eventHandler = eventHandler;
  this.jobFile = jobFile;
  this.partition = partition;

  //TODO:create the resource reqt for this Task attempt
  this.resourceCapability = recordFactory.newRecordInstance(Resource.class);
  this.resourceCapability.setMemory(
      getMemoryRequired(conf, taskId.getTaskType()));
  this.resourceCapability.setVirtualCores(
      getCpuRequired(conf, taskId.getTaskType()));
  this.resourceCapability.setGpuCores(
      getGpuRequired(conf, taskId.getTaskType()));

  this.dataLocalHosts = resolveHosts(dataLocalHosts);
  RackResolver.init(conf);
  this.dataLocalRacks = new HashSet<String>(); 
  for (String host : this.dataLocalHosts) {
    this.dataLocalRacks.add(RackResolver.resolve(host).getNetworkLocation());
  }

  locality = Locality.OFF_SWITCH;
  avataar = Avataar.VIRGIN;

  // This "this leak" is okay because the retained pointer is in an
  //  instance variable.
  stateMachine = stateMachineFactory.make(this);
}
 
源代码20 项目: neoscada   文件: MemoryBlock.java
/**
 * Create a new memory block
 * 
 * @param executor
 *            a single threaded executor for sending out events
 * @param hiveSource
 *            the source of the hive to export
 * @param properties
 *            properties to log on to the hive
 * @param logName
 *            an optional logging name
 */
public MemoryBlock ( final ScheduledExecutorService executor, final HiveSource hiveSource, final Properties properties, final String logName )
{
    final ReadWriteLock lock = new ReentrantReadWriteLock ();
    this.readLock = lock.readLock ();
    this.writeLock = lock.writeLock ();

    this.manager = new SingleSubscriptionManager ( executor, hiveSource, properties, logName );
    this.manager.start ();
}