Java Code Examples for java.util.concurrent.locks.ReadWriteLock#writeLock()

The following examples show how to use java.util.concurrent.locks.ReadWriteLock#writeLock() . 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: CmdDeleteConfValue.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public CmdDeleteConfValue(
    DbConnectionPool dbConnectionPoolRef,
    @Named(CoreModule.CTRL_CONF_LOCK) ReadWriteLock confLockRef,
    SystemConfRepository systemConfRepositoryRef,
    Provider<TransactionMgr> trnActProviderRef
)
{
    super(
        new String[]
        {
            "DelCfgVal"
        },
        "Deletes a configuration value",
        "Deletes an entry from the configuration.",
        PARAMETER_DESCRIPTIONS,
        null
    );

    dbConnectionPool = dbConnectionPoolRef;
    confWrLock = confLockRef.writeLock();
    systemConfRepository = systemConfRepositoryRef;
    trnActProvider = trnActProviderRef;
}
 
Example 2
Source File: CmdSetConfValue.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public CmdSetConfValue(
    DbConnectionPool dbConnectionPoolRef,
    @Named(CoreModule.CTRL_CONF_LOCK) ReadWriteLock confLockRef,
    SystemConfRepository systemConfRepositoryRef,
    Provider<TransactionMgr> trnActProviderRef
)
{
    super(
        new String[]
        {
            "SetCfgVal"
        },
        "Set configuration value",
        "Sets the value of a configuration entry.\nIf the entry does not exist, it is created.",
        PARAMETER_DESCRIPTIONS,
        null
    );

    dbConnectionPool = dbConnectionPoolRef;
    confWrLock = confLockRef.writeLock();
    systemConfRepository = systemConfRepositoryRef;
    trnActProvider = trnActProviderRef;
}
 
Example 3
Source File: LuceneEngine.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 4
Source File: Translog.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: RocksDBStore.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public RocksDBStore(String name, ColumnFamilyDescriptor family, ColumnFamilyHandle handle, RocksDB db, int stripes,
                    MetaManager metaManager) {
  super();
  this.family = family;
  this.name = name;
  this.db = db;
  this.parallel = stripes;
  this.handle = handle;
  this.sharedLocks = new AutoCloseableLock[stripes];
  this.exclusiveLocks = new AutoCloseableLock[stripes];
  this.metaManager = metaManager;

  for (int i = 0; i < stripes; i++) {
    ReadWriteLock core = new ReentrantReadWriteLock();
    sharedLocks[i] = new AutoCloseableLock(core.readLock());
    exclusiveLocks[i] = new AutoCloseableLock(core.writeLock());
  }

  registerMetrics();
}
 
Example 6
Source File: LocalTranslog.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: KeyAuthorizationKeyProvider.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * The constructor takes a {@link KeyProviderCryptoExtension} and an
 * implementation of <code>KeyACLs</code>. All calls are delegated to the
 * provider keyProvider after authorization check (if required)
 * @param keyProvider 
 * @param acls
 */
public KeyAuthorizationKeyProvider(KeyProviderCryptoExtension keyProvider,
    KeyACLs acls) {
  super(keyProvider, null);
  this.provider = keyProvider;
  this.acls = acls;
  ReadWriteLock lock = new ReentrantReadWriteLock(true);
  readLock = lock.readLock();
  writeLock = lock.writeLock();
}
 
Example 8
Source File: LocalizedResource.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: SimpleLRUCache.java    From dorado with Apache License 2.0 5 votes vote down vote up
private SimpleLRUCache(int capacity) {
	this.cache = new LRUMap<K, V>(capacity);
	ReadWriteLock lock = new ReentrantReadWriteLock();

	this.r = lock.readLock();
	this.w = lock.writeLock();
}
 
Example 10
Source File: MetadataExtracterRegistry.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public MetadataExtracterRegistry()
{
    // initialise lists
    extracters = new ArrayList<MetadataExtracter>(10);
    extracterCache = new HashMap<String, List<MetadataExtracter>>(17);
    embedderCache = new HashMap<String, List<MetadataEmbedder>>(17);

    // create lock objects for access to the cache
    ReadWriteLock extractionCacheLock = new ReentrantReadWriteLock();
    extracterCacheReadLock = extractionCacheLock.readLock();
    extracterCacheWriteLock = extractionCacheLock.writeLock();
}
 
Example 11
Source File: ConfigurationFactoryImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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 ();
}
 
Example 12
Source File: VersionedDelegatingStore.java    From Bats with Apache License 2.0 5 votes vote down vote up
public VersionedDelegatingStore(PersistentStore<V> store) {
  this.store = store;
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = new AutoCloseableLock(readWriteLock.readLock());
  writeLock = new AutoCloseableLock(readWriteLock.writeLock());
  version = 0;
}
 
Example 13
Source File: NaturalIdStatisticsImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 14
Source File: AuthenticationServiceImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public AuthenticationServiceImpl ()
{
    final ReadWriteLock lock = new ReentrantReadWriteLock ();
    this.readLock = lock.readLock ();
    this.writeLock = lock.writeLock ();
}
 
Example 15
Source File: TaskAttemptImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 16
Source File: JobImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 17
Source File: QueryStatisticsImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
QueryStatisticsImpl(String query) {
	this.query = query;
	ReadWriteLock lock = new ReentrantReadWriteLock();
	this.readLock = lock.readLock();
	this.writeLock = lock.writeLock();
}
 
Example 18
Source File: Switcher.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
public Switcher(final ReadWriteLock lock) {
    this(lock.readLock(), lock.writeLock(), new AtomicBoolean());
}
 
Example 19
Source File: TaskImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: MemoryBlock.java    From neoscada with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * 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 ();
}