List of usage examples for java.util.concurrent.locks ReentrantReadWriteLock ReentrantReadWriteLock
public ReentrantReadWriteLock()
From source file:org.apache.tajo.master.querymaster.Stage.java
public Stage(QueryMasterTask.QueryMasterTaskContext context, MasterPlan masterPlan, ExecutionBlock block) { this.context = context; this.masterPlan = masterPlan; this.block = block; this.eventHandler = context.getEventHandler(); ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); this.readLock = readWriteLock.readLock(); this.writeLock = readWriteLock.writeLock(); stateMachine = stateMachineFactory.make(this); stageState = stateMachine.getCurrentState(); }
From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl.java
public ContainerManagerImpl(Context context, ContainerExecutor exec, DeletionService deletionContext, NodeStatusUpdater nodeStatusUpdater, NodeManagerMetrics metrics, LocalDirsHandlerService dirsHandler) { super(ContainerManagerImpl.class.getName()); this.context = context; this.dirsHandler = dirsHandler; // ContainerManager level dispatcher. dispatcher = new AsyncDispatcher(); this.deletionService = deletionContext; this.metrics = metrics; rsrcLocalizationSrvc = createResourceLocalizationService(exec, deletionContext, context); addService(rsrcLocalizationSrvc);//from w w w.j av a 2 s. c om containersLauncher = createContainersLauncher(context, exec); addService(containersLauncher); this.exec = exec; this.nodeStatusUpdater = nodeStatusUpdater; // Start configurable services auxiliaryServices = new AuxServices(); auxiliaryServices.registerServiceListener(this); addService(auxiliaryServices); this.containersMonitor = new ContainersMonitorImpl(exec, dispatcher, this.context); addService(this.containersMonitor); dispatcher.register(ContainerEventType.class, new ContainerEventDispatcher()); dispatcher.register(ApplicationEventType.class, new ApplicationEventDispatcher()); dispatcher.register(LocalizationEventType.class, rsrcLocalizationSrvc); dispatcher.register(AuxServicesEventType.class, auxiliaryServices); dispatcher.register(ContainersMonitorEventType.class, containersMonitor); dispatcher.register(ContainersLauncherEventType.class, containersLauncher); addService(dispatcher); ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); this.cryptoMaterialUpdaterThreadPool = Executors.newFixedThreadPool(3, new ThreadFactoryBuilder() .setDaemon(true).setNameFormat("Container crypto material updater thread #%d").build()); }
From source file:org.apache.tajo.master.querymaster.SubQuery.java
public SubQuery(QueryMasterTask.QueryMasterTaskContext context, MasterPlan masterPlan, ExecutionBlock block, StorageManager sm) {/* ww w.j a v a2 s .com*/ this.context = context; this.masterPlan = masterPlan; this.block = block; this.sm = sm; this.eventHandler = context.getEventHandler(); ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); this.readLock = readWriteLock.readLock(); this.writeLock = readWriteLock.writeLock(); stateMachine = stateMachineFactory.make(this); subQueryState = stateMachine.getCurrentState(); }
From source file:org.apache.tez.dag.app.dag.impl.DAGImpl.java
public DAGImpl(TezDAGID dagId, TezConfiguration conf, DAGPlan jobPlan, EventHandler eventHandler, TaskAttemptListener taskAttemptListener, JobTokenSecretManager jobTokenSecretManager, Credentials fsTokenCredentials, Clock clock, String appUserName, TaskHeartbeatHandler thh, AppContext appContext) {/*from w ww . jav a 2 s . c om*/ this.dagId = dagId; this.jobPlan = jobPlan; this.conf = conf; this.dagName = (jobPlan.getName() != null) ? jobPlan.getName() : "<missing app name>"; this.userName = appUserName; this.clock = clock; this.appContext = appContext; this.queueName = conf.get(MRJobConfig.QUEUE_NAME, "default"); this.taskAttemptListener = taskAttemptListener; this.taskHeartbeatHandler = thh; this.eventHandler = eventHandler; ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); this.readLock = readWriteLock.readLock(); this.writeLock = readWriteLock.writeLock(); this.fsTokens = fsTokenCredentials; this.jobTokenSecretManager = jobTokenSecretManager; this.aclsManager = new ApplicationACLsManager(conf); // This "this leak" is okay because the retained pointer is in an // instance variable. stateMachine = stateMachineFactory.make(this); }
From source file:org.apache.tajo.querymaster.Stage.java
public Stage(QueryMasterTask.QueryMasterTaskContext context, MasterPlan masterPlan, ExecutionBlock block) { this.context = context; this.masterPlan = masterPlan; this.block = block; this.eventHandler = context.getEventHandler(); this.rpcParams = RpcParameterFactory.get(context.getConf()); ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); this.readLock = readWriteLock.readLock(); this.writeLock = readWriteLock.writeLock(); stateMachine = stateMachineFactory.make(this); stageState = stateMachine.getCurrentState(); }
From source file:org.apache.hadoop.mapreduce.v2.app.job.impl.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();// ww w. java 2 s. c o m 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; }
From source file:com.edgenius.wiki.rss.RSSServiceImpl.java
/** * @param spaceUid// w ww . j ava 2 s. c o m * @param spaceUname * @param viewer * @param skipSecurityCheck * @return * @throws FeedException */ private Document getFeedDom(Integer spaceUid, String spaceUname, User viewer, boolean skipSecurityCheck) throws FeedException { ReentrantReadWriteLock lock = null; Document dom; try { File feedFile = new File(FileUtil.getFullPath(rssRoot.getFile().getAbsolutePath(), spaceUid + ".xml")); if (!feedFile.exists()) { createFeed(spaceUname); } //do read lock! must after createFeed possibility, otherwise, deadlock lock = lockMap.get(spaceUid.toString()); if (lock == null) { lock = new ReentrantReadWriteLock(); lockMap.put(spaceUid.toString(), lock); } lock.readLock().lock(); //!!! DON'T USE JDOM - although I test DOM, JDOM, DOM4J: JDOM is fastest. And DOM and DOM4J almost 2 time slow. But //!!! JDOM is not thread safe, an infinite looping can happen while this method reading different XML source, //in different thread, and SAXBuild are different instance! The problem is mostly caused by NameSpace.getNamespace(), //which using static HashMap and cause HashMap dead lock!!! DocumentBuilder builder = xmlBuilderPool.poll(); if (builder == null) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setCoalescing(true); factory.setIgnoringComments(true); builder = factory.newDocumentBuilder(); } dom = builder.parse(feedFile); xmlBuilderPool.add(builder); } catch (Exception e) { log.error("Unable get feed " + spaceUname + " with excpetion ", e); throw new FeedException("Unable get feed " + spaceUname + " with excpetion " + e); } finally { if (lock != null) lock.readLock().unlock(); } if (dom == null) { log.error("Unable get feed " + spaceUname); throw new FeedException("Unable get feed " + spaceUname); } //~~~~~~~~~~~~ Security filter if (!skipSecurityCheck) { //need filter out the page that viewer has not permission to read. List<Node> forbidPageUuidList = new ArrayList<Node>(); String pageUuid; Node ele; NodeList list = dom.getElementsByTagName(PageRSSModule.NS_PREFIX + ":" + PageRSSModule.PAGE_UUID); int len = list.getLength(); for (int idx = 0; idx < len; idx++) { ele = list.item(idx); pageUuid = ele.getTextContent(); if (!securityService.isAllowPageReading(spaceUname, pageUuid, viewer)) { log.info("User " + (viewer == null ? "anonymous" : viewer.getUsername()) + " has not reading permission for pageUuid " + pageUuid + " on space " + spaceUname + ". Feed item of this page is removed from RSS output."); forbidPageUuidList.add(ele.getParentNode()); } } if (forbidPageUuidList.size() > 0) { NodeList cl = dom.getElementsByTagName(PageRSSModule.CHANNEL); if (cl.getLength() > 0) { //only one channel tag! Node channel = cl.item(0); for (Node element : forbidPageUuidList) { channel.removeChild(element); } } } } return dom; }
From source file:org.apache.tez.dag.app.rm.container.AMContainerImpl.java
public AMContainerImpl(Container container, ContainerHeartbeatHandler chh, TaskAttemptListener tal, AppContext appContext) {/*from w ww . ja v a 2s . co m*/ ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(); this.readLock = rwLock.readLock(); this.writeLock = rwLock.writeLock(); this.container = container; this.containerId = container.getId(); this.eventHandler = appContext.getEventHandler(); this.appContext = appContext; this.containerHeartbeatHandler = chh; this.taskAttemptListener = tal; this.failedAssignments = new LinkedList<TezTaskAttemptID>(); this.noAllocationContainerTask = WAIT_TASK; this.stateMachine = stateMachineFactory.make(this); }
From source file:org.apache.tez.dag.app.dag.impl.VertexImpl.java
public VertexImpl(TezVertexID vertexId, VertexPlan vertexPlan, String vertexName, TezConfiguration conf, EventHandler eventHandler, TaskAttemptListener taskAttemptListener, Token<JobTokenIdentifier> jobToken, Credentials fsTokenCredentials, Clock clock, // TODO: Recovery //Map<TaskId, TaskInfo> completedTasksFromPreviousRun, // TODO Metrics //MRAppMetrics metrics, TaskHeartbeatHandler thh, AppContext appContext, VertexLocationHint vertexLocationHint) { this.vertexId = vertexId; this.vertexPlan = vertexPlan; this.vertexName = vertexName; this.conf = conf; //this.metrics = metrics; this.clock = clock; // TODO: Recovery //this.completedTasksFromPreviousRun = completedTasksFromPreviousRun; this.appContext = appContext; this.taskAttemptListener = taskAttemptListener; this.taskHeartbeatHandler = thh; this.eventHandler = eventHandler; ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); this.readLock = readWriteLock.readLock(); this.writeLock = readWriteLock.writeLock(); this.fsTokens = fsTokenCredentials; this.jobToken = jobToken; this.committer = new NullVertexOutputCommitter(); this.vertexLocationHint = vertexLocationHint; this.taskResource = DagTypeConverters.createResourceRequestFromTaskConfig(vertexPlan.getTaskConfig()); this.processorDescriptor = DagTypeConverters .convertProcessorDescriptorFromDAGPlan(vertexPlan.getProcessorDescriptor()); this.localResources = DagTypeConverters .createLocalResourceMapFromDAGPlan(vertexPlan.getTaskConfig().getLocalResourceList()); this.environment = DagTypeConverters .createEnvironmentMapFromDAGPlan(vertexPlan.getTaskConfig().getEnvironmentSettingList()); this.javaOpts = vertexPlan.getTaskConfig().hasJavaOpts() ? vertexPlan.getTaskConfig().getJavaOpts() : null; this.vertexContext = new VertexContext(getDAGId(), this.processorDescriptor.getUserPayload(), this.vertexId, getApplicationAttemptId());//from w ww . j a va2 s . co m // This "this leak" is okay because the retained pointer is in an // instance variable. stateMachine = stateMachineFactory.make(this); }
From source file:org.rhq.core.pc.inventory.ResourceContainer.java
private Object readResolve() throws java.io.ObjectStreamException { this.facetAccessLock = new ReentrantReadWriteLock(); return this; }