Example usage for java.util.concurrent.locks ReadWriteLock writeLock

List of usage examples for java.util.concurrent.locks ReadWriteLock writeLock

Introduction

In this page you can find the example usage for java.util.concurrent.locks ReadWriteLock writeLock.

Prototype

Lock writeLock();

Source Link

Document

Returns the lock used for writing.

Usage

From source file:org.apache.tajo.master.querymaster.SubQuery.java

public SubQuery(QueryMasterTask.QueryMasterTaskContext context, MasterPlan masterPlan, ExecutionBlock block,
        StorageManager sm) {//from w ww .j  ava2s  . c o m
    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.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  av a  2 s.c  om*/

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

From source file:com.cloudera.oryx.als.serving.ServerRecommender.java

@Override
public void setPreference(String userID, String itemID, float value) {

    // Record datum
    try {/*ww w .  j  a  v  a  2  s  .  c o m*/
        generationManager.append(userID, itemID, value);
    } catch (IOException ioe) {
        log.warn("Could not append datum; continuing", ioe);
    }

    Generation generation;
    try {
        generation = getCurrentGeneration();
    } catch (NotReadyException nre) {
        // Corner case -- no model ready so all we can do is record (above). Don't fail the request.
        return;
    }

    long longUserID = StringLongMapping.toLong(userID);
    long longItemID = StringLongMapping.toLong(itemID);

    float[] userFeatures = getFeatures(longUserID, generation.getX(), generation.getXLock());

    boolean newItem;
    Lock yReadLock = generation.getYLock().readLock();
    yReadLock.lock();
    try {
        newItem = generation.getY().get(longItemID) == null;
    } finally {
        yReadLock.unlock();
    }
    if (newItem) {
        generation.getCandidateFilter().addItem(itemID);
    }

    float[] itemFeatures = getFeatures(longItemID, generation.getY(), generation.getYLock());

    updateFeatures(userFeatures, itemFeatures, value, generation);

    LongObjectMap<LongSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs != null) {
        LongSet userKnownItemIDs;
        ReadWriteLock knownItemLock = generation.getKnownItemLock();
        Lock knownItemReadLock = knownItemLock.readLock();
        knownItemReadLock.lock();
        try {
            userKnownItemIDs = knownItemIDs.get(longUserID);
            if (userKnownItemIDs == null) {
                userKnownItemIDs = new LongSet();
                Lock knownItemWriteLock = knownItemLock.writeLock();
                knownItemReadLock.unlock();
                knownItemWriteLock.lock();
                try {
                    knownItemIDs.put(longUserID, userKnownItemIDs);
                } finally {
                    knownItemReadLock.lock();
                    knownItemWriteLock.unlock();
                }
            }
        } finally {
            knownItemReadLock.unlock();
        }

        synchronized (userKnownItemIDs) {
            userKnownItemIDs.add(longItemID);
        }
    }
}

From source file:com.doculibre.constellio.wicket.panels.admin.indexing.AdminIndexingPanel.java

public AdminIndexingPanel(String id) {
    super(id);//from w  w w. ja  v a 2 s . c  o  m
    sizeDisk = 0;
    indexedRecords = 0;

    add(new AjaxSelfUpdatingTimerBehavior(Duration.ONE_SECOND));
    // add(new AbstractAjaxTimerBehavior(Duration.ONE_SECOND) {
    // @Override
    // protected void onTimer(AjaxRequestTarget target) {
    // // Do nothing, will prevent page from expiring
    // }
    // });

    connectorsModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            List<ConnectorInstance> connectors;
            RecordCollection collection = getRecordCollection();
            if (collection.isFederationOwner()) {
                FederationServices federationServices = ConstellioSpringUtils.getFederationServices();
                connectors = federationServices.listConnectors(collection);
            } else {
                connectors = new ArrayList<ConnectorInstance>(collection.getConnectorInstances());
            }
            return connectors;
        }
    };

    manageConnectorsLink = new Link("manageConnectorsLink") {
        @Override
        public void onClick() {
            AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            adminCollectionPanel.setSelectedTab(AdminCollectionPanel.CONNECTORS_MANAGEMENT_PANEL);
        }

        @Override
        public boolean isVisible() {
            boolean visible = super.isVisible();
            if (visible) {
                RecordCollection collection = getRecordCollection();
                visible = collection.getConnectorInstances().isEmpty();
            }
            return visible;
        }
    };

    synchronizeIndexFieldsLink = new Link("synchronizeIndexFieldsLink") {
        @Override
        public void onClick() {
            RecordCollection collection = getRecordCollection();

            RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
            SolrServices solrServices = ConstellioSpringUtils.getSolrServices();

            solrServices.updateSchemaFields(collection);
            solrServices.initCore(collection);

            EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
            if (!entityManager.getTransaction().isActive()) {
                entityManager.getTransaction().begin();
            }
            collectionServices.markSynchronized(collection);
            entityManager.getTransaction().commit();

            IndexingManager indexingManager = IndexingManager.get(collection);
            if (!indexingManager.isActive()) {
                indexingManager.startIndexing();
            }
        }

        @Override
        public boolean isVisible() {
            boolean visible = super.isVisible();
            if (visible) {
                RecordCollection collection = getRecordCollection();
                visible = collection.isSynchronizationRequired();
            }
            return visible;
        }
    };

    manageIndexFieldsLink = new Link("manageIndexFieldsLink") {
        @Override
        public void onClick() {
            AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            adminCollectionPanel.setSelectedTab(AdminCollectionPanel.INDEX_FIELDS_MANAGEMENT_PANEL);
        }
    };

    recordCountLabel = new Label("recordCount", new LoadableDetachableModel() {
        @Override
        protected Object load() {
            RecordCollection collection = getRecordCollection();
            return StatusManager.countTraversedRecords(collection);
        }
    });

    deleteAllLink = new Link("deleteAllLink") {
        @Override
        public void onClick() {
            RecordCollection collection = getRecordCollection();
            RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
            FederationServices federationServices = ConstellioSpringUtils.getFederationServices();

            ReadWriteLock collectionLock = recordServices.getLock(collection.getName());
            collectionLock.writeLock().lock();
            try {

                ConstellioPersistenceUtils.beginTransaction();
                recordServices.markRecordsForDeletion(collection);
                if (collection.isFederationOwner()) {
                    List<RecordCollection> includedCollections = federationServices
                            .listIncludedCollections(collection);
                    for (RecordCollection includedCollection : includedCollections) {
                        recordServices.markRecordsForDeletion(includedCollection);
                    }
                }
                SolrServer solrServer = SolrCoreContext.getSolrServer(collection);
                try {
                    solrServer.commit();
                    solrServer.optimize();
                } catch (Throwable t) {
                    try {
                        solrServer.rollback();
                    } catch (Exception e) {
                        throw new RuntimeException(t);
                    }
                }
            } finally {
                try {
                    ConstellioPersistenceUtils.finishTransaction(false);
                } finally {
                    collectionLock.writeLock().unlock();
                }
            }

            // RecordCollection collection = getRecordCollection();
            //
            // ConnectorManagerServices connectorManagerServices =
            // ConstellioSpringUtils.getConnectorManagerServices();
            // ConnectorManager connectorManager =
            // connectorManagerServices.getDefaultConnectorManager();
            // for (ConnectorInstance connectorInstance :
            // collection.getConnectorInstances()) {
            // String connectorName = connectorInstance.getName();
            // connectorManagerServices.disableConnector(connectorManager,
            // connectorName);
            // }
            //
            // IndexingManager indexingManager =
            // IndexingManager.get(collection);
            // indexingManager.deleteAll();
            // indexingManager.optimize();
            // while (indexingManager.isOptimizing()) {
            // try {
            // Thread.sleep(200);
            // } catch (InterruptedException e) {
            // e.printStackTrace();
            // }
            // }
        }

        @Override
        protected CharSequence getOnClickScript(CharSequence url) {
            String confirmMsg = getLocalizer().getString("confirmDeleteAll", AdminIndexingPanel.this)
                    .replace("'", "\\'");
            return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url
                    + "';} else { return false; }";
        }
    };

    indexedRecordCountLabel = new Label("indexedRecordCount", new LoadableDetachableModel() {
        @Override
        protected Object load() {
            RecordCollection collection = getRecordCollection();
            return StatusManager.countIndexedRecords(collection);
        }
    });

    controlIndexingButtons = new WebMarkupContainer("controlIndexingButtons");
    controlIndexingButtons.setOutputMarkupId(true);

    reindexAllLink = new Link("reindexAllLink") {
        @Override
        public void onClick() {
            RecordCollection collection = getRecordCollection();
            final String collectioName = collection.getName();
            final Long collectionId = collection.getId();

            new Thread() {
                @Override
                public void run() {
                    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
                    ReadWriteLock collectionLock = recordServices.getLock(collectioName);
                    collectionLock.writeLock().lock();
                    try {
                        EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
                        if (!entityManager.getTransaction().isActive()) {
                            entityManager.getTransaction().begin();
                        }

                        RecordCollectionServices collectionServices = ConstellioSpringUtils
                                .getRecordCollectionServices();
                        FederationServices federationServices = ConstellioSpringUtils.getFederationServices();
                        RecordCollection collection = collectionServices.get(collectionId);
                        try {
                            recordServices.markRecordsForUpdateIndex(collection);
                            if (collection.isFederationOwner()) {
                                List<RecordCollection> includedCollections = federationServices
                                        .listIncludedCollections(collection);
                                for (RecordCollection includedCollection : includedCollections) {
                                    recordServices.markRecordsForUpdateIndex(includedCollection);
                                }
                            }
                            SolrServer solrServer = SolrCoreContext.getSolrServer(collection);
                            try {
                                // solrServer.commit();
                                solrServer.optimize();
                            } catch (Throwable t) {
                                try {
                                    solrServer.rollback();
                                } catch (Exception e) {
                                    throw new RuntimeException(t);
                                }
                            }
                        } finally {
                            ConstellioPersistenceUtils.finishTransaction(false);
                        }
                    } finally {
                        collectionLock.writeLock().unlock();
                    }
                }

            }.start();
        }

        @Override
        protected CharSequence getOnClickScript(CharSequence url) {
            String confirmMsg = getLocalizer().getString("confirmReindexAll", AdminIndexingPanel.this)
                    .replace("'", "\\'");
            return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url
                    + "';} else { return false; }";
        }
    };

    resumeIndexingLink = new Link("resumeIndexingLink") {
        @Override
        public void onClick() {
            RecordCollection collection = getRecordCollection();
            IndexingManager indexingManager = IndexingManager.get(collection);
            if (!indexingManager.isActive()) {
                indexingManager.startIndexing(false);
            }
        }

        @Override
        public boolean isVisible() {
            // boolean visible = super.isVisible();
            // if (visible) {
            // RecordCollection collection = getRecordCollection();
            // IndexingManager indexingManager =
            // IndexingManager.get(collection);
            // visible = !collection.isSynchronizationRequired() &&
            // !indexingManager.isActive();
            // }
            // return visible;
            return false;
        }
    };

    optimizeLink = new Link("optimizeLink") {
        @Override
        public void onClick() {
            RecordCollection collection = getRecordCollection();
            final Long collectionId = collection.getId();
            new Thread() {
                @Override
                public void run() {
                    RecordCollectionServices collectionServices = ConstellioSpringUtils
                            .getRecordCollectionServices();
                    RecordCollection collection = collectionServices.get(collectionId);
                    SolrServer solrServer = SolrCoreContext.getSolrServer(collection);
                    try {
                        solrServer.optimize();
                    } catch (Throwable t) {
                        try {
                            solrServer.rollback();
                        } catch (Exception e) {
                            throw new RuntimeException(t);
                        }
                    }
                    // IndexingManager indexingManager =
                    // IndexingManager.get(collection);
                    // if (indexingManager.isActive() &&
                    // !indexingManager.isOptimizing()) {
                    // indexingManager.optimize();
                    // }
                }
            }.start();
        }

        @Override
        protected CharSequence getOnClickScript(CharSequence url) {
            String confirmMsg = getLocalizer().getString("confirmOptimize", AdminIndexingPanel.this)
                    .replace("'", "\\'");
            return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url
                    + "';} else { return false; }";
        }

        @Override
        public boolean isVisible() {
            // boolean visible = super.isVisible();
            // if (visible) {
            // RecordCollection collection = getRecordCollection();
            // IndexingManager indexingManager =
            // IndexingManager.get(collection);
            // visible = indexingManager.isActive();
            // }
            // return visible;
            return true;
        }

        @Override
        public boolean isEnabled() {
            // boolean enabled = super.isEnabled();
            // if (enabled) {
            // RecordCollection collection = getRecordCollection();
            // IndexingManager indexingManager =
            // IndexingManager.get(collection);
            // enabled = indexingManager.isActive() &&
            // !indexingManager.isOptimizing();
            // }
            // return enabled;
            return true;
        }
    };

    indexSizeOnDiskLabel = new Label("indexSizeOnDisk", new LoadableDetachableModel() {
        @Override
        protected Object load() {
            RecordCollection collection = getRecordCollection();
            return StatusManager.getSizeOnDisk(collection);
        }
    });

    connectorTraversalStatesListView = new ListView("connectorTraversalStates", connectorsModel) {
        @Override
        protected void populateItem(ListItem item) {
            ConnectorInstance connectorInstance = (ConnectorInstance) item.getModelObject();
            final ReloadableEntityModel<ConnectorInstance> connectorInstanceModel = new ReloadableEntityModel<ConnectorInstance>(
                    connectorInstance);
            Label displayNameLabel = new Label("displayName", connectorInstance.getDisplayName());
            Label lastTraversalDateLabel = new Label("latestTraversalDate", new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                    Date lastTraversalDate = StatusManager.getLastTraversalDate(connectorInstance);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    return lastTraversalDate != null ? sdf.format(lastTraversalDate) : "---";
                }

                @Override
                public void detach() {
                    connectorInstanceModel.detach();
                    super.detach();
                }
            });

            Link restartTraversalLink = new Link("restartTraversalLink") {
                @Override
                public void onClick() {
                    ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                    ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils
                            .getConnectorManagerServices();
                    ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager();
                    connectorManagerServices.restartTraversal(connectorManager, connectorInstance.getName());
                }

                @Override
                protected CharSequence getOnClickScript(CharSequence url) {
                    String confirmMsg = getLocalizer()
                            .getString("confirmRestartTraversal", AdminIndexingPanel.this).replace("'", "\\'");
                    return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url
                            + "';} else { return false; }";
                }

                @Override
                public boolean isVisible() {
                    ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                    RecordCollection connectorInstanceCollection = connectorInstance.getRecordCollection();
                    ConstellioUser user = ConstellioSession.get().getUser();
                    return super.isVisible() && user.hasAdminPermission(connectorInstanceCollection);
                }
            };

            Link disableConnectorLink = new Link("disableConnectorLink") {
                @Override
                public void onClick() {
                    ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                    String connectorName = connectorInstance.getName();
                    ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils
                            .getConnectorManagerServices();
                    ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager();
                    connectorManagerServices.disableConnector(connectorManager, connectorName);
                }

                @Override
                protected CharSequence getOnClickScript(CharSequence url) {
                    String confirmMsg = getLocalizer()
                            .getString("confirmDisableConnector", AdminIndexingPanel.this).replace("'", "\\'");
                    return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url
                            + "';} else { return false; }";
                }

                @Override
                public boolean isVisible() {
                    boolean visible = super.isVisible();
                    if (visible) {
                        ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                        String connectorName = connectorInstance.getName();
                        ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils
                                .getConnectorManagerServices();
                        ConnectorManager connectorManager = connectorManagerServices
                                .getDefaultConnectorManager();
                        visible = connectorManagerServices.isConnectorEnabled(connectorManager, connectorName);
                        if (visible) {
                            RecordCollection connectorInstanceCollection = connectorInstance
                                    .getRecordCollection();
                            ConstellioUser user = ConstellioSession.get().getUser();
                            visible = user.hasAdminPermission(connectorInstanceCollection);
                        }
                    }
                    return visible;
                }
            };

            Link enableConnectorLink = new Link("enableConnectorLink") {
                @Override
                public void onClick() {
                    ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                    String connectorName = connectorInstance.getName();
                    ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils
                            .getConnectorManagerServices();
                    ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager();
                    connectorManagerServices.enableConnector(connectorManager, connectorName);
                }

                @Override
                protected CharSequence getOnClickScript(CharSequence url) {
                    String confirmMsg = getLocalizer()
                            .getString("confirmEnableConnector", AdminIndexingPanel.this).replace("'", "\\'");
                    return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url
                            + "';} else { return false; }";
                }

                @Override
                public boolean isVisible() {
                    boolean visible = super.isVisible();
                    if (visible) {
                        ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                        String connectorName = connectorInstance.getName();
                        ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils
                                .getConnectorManagerServices();
                        ConnectorManager connectorManager = connectorManagerServices
                                .getDefaultConnectorManager();
                        visible = !connectorManagerServices.isConnectorEnabled(connectorManager, connectorName);
                        if (visible) {
                            RecordCollection connectorInstanceCollection = connectorInstance
                                    .getRecordCollection();
                            ConstellioUser user = ConstellioSession.get().getUser();
                            visible = user.hasAdminPermission(connectorInstanceCollection);
                        }
                    }
                    return visible;
                }
            };

            item.add(displayNameLabel);
            item.add(lastTraversalDateLabel);
            item.add(restartTraversalLink);
            item.add(disableConnectorLink);
            item.add(enableConnectorLink);
        }
    };

    latestIndexedRecordsTextArea = new LoggingTextArea("latestIndexedRecordsTextArea",
            new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    RecordCollection collection = getRecordCollection();
                    return StatusManager.listLastIndexedRecords(collection);
                }
            }, refreshTimeMillis);

    connectorTraversalTextAreasListView = new ListView("connectorTraversalTextAreas", connectorsModel) {
        @Override
        protected void populateItem(ListItem item) {
            ConnectorInstance connectorInstance = (ConnectorInstance) item.getModelObject();
            final ReloadableEntityModel<ConnectorInstance> connectorInstanceModel = new ReloadableEntityModel<ConnectorInstance>(
                    connectorInstance);
            Label displayNameLabel = new Label("displayName", connectorInstance.getDisplayName());

            LoggingTextArea traversalTextArea = new LoggingTextArea("traversalTextArea",
                    new LoadableDetachableModel() {
                        @Override
                        protected Object load() {
                            ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
                            return StatusManager.listLastTraversedRecords(connectorInstance);
                        }
                    }, refreshTimeMillis) {
                @Override
                public void detachModels() {
                    connectorInstanceModel.detach();
                    super.detachModels();
                }
            };

            item.add(displayNameLabel);
            item.add(traversalTextArea);
        }
    };
    // connectorTextAreasListView.setReuseItems(true);

    add(manageConnectorsLink);
    add(synchronizeIndexFieldsLink);
    add(manageIndexFieldsLink);
    add(recordCountLabel);
    add(deleteAllLink);
    add(indexedRecordCountLabel);
    add(controlIndexingButtons);
    controlIndexingButtons.add(reindexAllLink);
    controlIndexingButtons.add(resumeIndexingLink);
    controlIndexingButtons.add(optimizeLink);
    add(indexSizeOnDiskLabel);
    add(connectorTraversalStatesListView);
    add(latestIndexedRecordsTextArea);
    add(connectorTraversalTextAreasListView);

    /*
     * Quotas Part of the code :
     * antoine.timonnier@gmail.com
     */

    //Loading the size of the disk
    IModel model1 = new LoadableDetachableModel() {
        protected Object load() {
            return getsizeDisk();
        }
    };

    //Loading the number of documents indexed
    IModel model2 = new LoadableDetachableModel() {
        protected Object load() {
            return getindexedRecords();
        }
    };

    //Boolean that is true if both of the quotas are reached
    boolean bothQuotas = false;
    QuotasManagerImpl quotasManager = new QuotasManagerImpl();
    //TODO connect quotas manager with the quotas.properties
    /*double quotaSizeDisk = quotasManager.getQuotaSizeDisk();
    double quotaIndexedRecords = quotasManager.getQuotaIndexedRecords();
    double quotaPercentage = quotasManager.getQuotaPercentage();*/
    double quotaSizeDisk = 1;
    double quotaIndexedRecords = 1;
    double quotaPercentage = 70;
    double percentageSizeDisk = (sizeDisk * 100) / quotaSizeDisk;
    double percentageIndexedRecords = (indexedRecords * 100) / quotaIndexedRecords;

    //if the size of the disk is upper the quota percentage and doesn't reach the quota (lower than 100%)
    if (quotaPercentage < percentageSizeDisk && percentageSizeDisk < 100) {
        final String textPercentageSizeDisk = "Vous tes rendu  " + Double.toString(percentageSizeDisk)
                + "% de votre quota d'espace disque, veuillez contacter un administrateur !";
        configurePopUp(popUpPercentageSizeDisk, textPercentageSizeDisk, "Attention");
    }
    add(popUpPercentageSizeDisk);

    //if the number of doc indexed is upper the quota percentage and doesn't reach the quota (lower than 100%)
    if (quotaIndexedRecords < percentageIndexedRecords && percentageIndexedRecords < 100) {
        final String textPercentageIndexedRecords = "Vous tes rendu  " + Double.toString(percentageSizeDisk)
                + "% de votre quota de nombre de documents indexs, veuillez contacter un administrateur !";
        configurePopUp(popUpPercentageIndexedRecords, textPercentageIndexedRecords, "Attention");
    }
    add(popUpPercentageIndexedRecords);

    //Adding a pop up if both of the quotas are reached
    popUpBothQuotas = new ModalWindow("popUpBothQuotas");
    if (sizeDisk > quotaSizeDisk && indexedRecords > quotaIndexedRecords) {
        bothQuotas = true;
        // Sending the email
        // TODO sendEmail(String hostName, int smtpPort,
        // DefaultAuthenticator authenticator, String sender, String
        // subject, String message, String receiver);
        // TODO lock the indexing
        //Configuration of the popUp
        final String textBothQuotas = "Vous avez dpass votre quota d'espace disque et votre quotat de document indexs, veuillez contacter un administrateur";
        configurePopUp(popUpBothQuotas, textBothQuotas, "Attention");
    }
    add(popUpBothQuotas);

    //Adding a pop up if the size disk quota is reached
    popUpSizeDisk = new ModalWindow("popUpSizeDisk");
    boolean sizeDiskSuperior = sizeDisk > quotaSizeDisk;
    if (sizeDiskSuperior && bothQuotas == false) {
        /* Sending the email
        try {
           sendEmail("smtp.googlemail.com", 465, new DefaultAuthenticator("antoine.timonnier@gmail.com","quenellede300"), "antoine.timonnier@gmail.com", "constellio", "blabla", "antoine.timonnier@gmail.com");
        } catch (EmailException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
        } */
        // TODO lock
        // Configuration of the popup
        final String textSizeDisk = "Attention, vous avez dpass votre quota d'espace disque, veuillez contacter un administrateur";
        configurePopUp(popUpSizeDisk, textSizeDisk, "Attention");
    }
    add(popUpSizeDisk);

    //Adding a pop up if the indexed records quota is reached
    popUpIndexedRecords = new ModalWindow("popUpIndexedRecords");
    if (indexedRecords > quotaIndexedRecords && bothQuotas == false) {
        // sending the email
        // TODO sendEmail(String hostName, int smtpPort,
        // DefaultAuthenticator authenticator, String sender, String
        // subject, String message, String receiver);
        // TODO lock
        // Configuration of the popup
        final String textIndexedRecords = "Attention, vous avez dpass votre quota de documents indexs, veuillez contacter un administrateur. boolean both = "
                + bothQuotas;
        configurePopUp(popUpIndexedRecords, textIndexedRecords, "Attention");
    }
    add(popUpIndexedRecords);

}

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:net.myrrix.online.ServerRecommender.java

public void setPreference(long userID, long itemID, float value, boolean bulk) {

    // Record datum
    try {//w  w  w.ja v a  2 s . c o m
        generationManager.append(userID, itemID, value, bulk);
    } catch (IOException ioe) {
        log.warn("Could not append datum; continuing", ioe);
    }

    Generation generation;
    try {
        generation = getCurrentGeneration();
    } catch (NotReadyException nre) {
        // Corner case -- no model ready so all we can do is record (above). Don't fail the request.
        return;
    }

    float[] userFeatures = getFeatures(userID, generation.getX(), generation.getXLock());

    boolean newItem;
    Lock yReadLock = generation.getYLock().readLock();
    yReadLock.lock();
    try {
        newItem = generation.getY().get(itemID) == null;
    } finally {
        yReadLock.unlock();
    }
    if (newItem) {
        generation.getCandidateFilter().addItem(itemID);
    }

    float[] itemFeatures = getFeatures(itemID, generation.getY(), generation.getYLock());

    updateFeatures(userFeatures, itemFeatures, value, generation);

    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs != null) {
        FastIDSet userKnownItemIDs;
        ReadWriteLock knownItemLock = generation.getKnownItemLock();
        Lock knownItemReadLock = knownItemLock.readLock();
        knownItemReadLock.lock();
        try {
            userKnownItemIDs = knownItemIDs.get(userID);
            if (userKnownItemIDs == null) {
                userKnownItemIDs = new FastIDSet();
                Lock knownItemWriteLock = knownItemLock.writeLock();
                knownItemReadLock.unlock();
                knownItemWriteLock.lock();
                try {
                    knownItemIDs.put(userID, userKnownItemIDs);
                } finally {
                    knownItemReadLock.lock();
                    knownItemWriteLock.unlock();
                }
            }
        } finally {
            knownItemReadLock.unlock();
        }

        synchronized (userKnownItemIDs) {
            userKnownItemIDs.add(itemID);
        }
    }

    updateClusters(userID, userFeatures, generation.getUserClusters(),
            generation.getUserClustersLock().readLock());
    updateClusters(itemID, itemFeatures, generation.getItemClusters(),
            generation.getItemClustersLock().readLock());
}

From source file:org.apache.hadoop.mapreduce.v2.app.job.impl.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.reporterUserName = System.getProperty("user.name");
    this.jobACLs = aclsManager.constructJobACLs(conf);

    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Job Fail Wait Timeout Monitor #%d")
            .setDaemon(true).build();//from w  w  w.  j  av  a 2 s. co  m
    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);
}

From source file:org.apache.hadoop.mapreduce.v2.app.job.impl.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);/*from  www  .  j  a v  a 2 s.co  m*/
    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.setMemorySize(getMemoryRequired(conf, taskId.getTaskType()));
    this.resourceCapability.setVirtualCores(getCpuRequired(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);
}

From source file:com.cloudera.oryx.als.serving.ServerRecommender.java

@Override
public void removePreference(String userID, String itemID) {

    // Record datum
    try {/* ww w  .j  a v  a 2  s .co m*/
        generationManager.remove(userID, itemID);
    } catch (IOException ioe) {
        log.warn("Could not append datum; continuing", ioe);
    }

    Generation generation;
    try {
        generation = getCurrentGeneration();
    } catch (NotReadyException nre) {
        // Corner case -- no model ready so all we can do is record (above). Don't fail the request.
        return;
    }

    long longUserID = StringLongMapping.toLong(userID);
    long longItemID = StringLongMapping.toLong(itemID);

    ReadWriteLock knownItemLock = generation.getKnownItemLock();

    boolean removeUser = false;
    LongObjectMap<LongSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs != null) {

        Lock knownItemReadLock = knownItemLock.readLock();
        LongSet userKnownItemIDs;
        knownItemReadLock.lock();
        try {
            userKnownItemIDs = knownItemIDs.get(longUserID);
        } finally {
            knownItemReadLock.unlock();
        }

        if (userKnownItemIDs == null) {
            // Doesn't exist? So ignore this request
            return;
        }

        synchronized (userKnownItemIDs) {
            if (!userKnownItemIDs.remove(longItemID)) {
                // Item unknown, so ignore this request
                return;
            }
            removeUser = userKnownItemIDs.isEmpty();
        }
    }

    // We can proceed with the request

    LongObjectMap<float[]> X = generation.getX();

    ReadWriteLock xLock = generation.getXLock();

    if (removeUser) {

        Lock knownItemWriteLock = knownItemLock.writeLock();
        knownItemWriteLock.lock();
        try {
            knownItemIDs.remove(longUserID);
        } finally {
            knownItemWriteLock.unlock();
        }

        Lock xWriteLock = xLock.writeLock();
        xWriteLock.lock();
        try {
            X.remove(longUserID);
        } finally {
            xWriteLock.unlock();
        }

    }

}

From source file:net.myrrix.online.ServerRecommender.java

private void removePreference(long userID, long itemID, boolean bulk) {

    // Record datum
    try {/*from w  w w .  ja v  a  2  s  .  com*/
        generationManager.remove(userID, itemID, bulk);
    } catch (IOException ioe) {
        log.warn("Could not append datum; continuing", ioe);
    }

    Generation generation;
    try {
        generation = getCurrentGeneration();
    } catch (NotReadyException nre) {
        // Corner case -- no model ready so all we can do is record (above). Don't fail the request.
        return;
    }

    ReadWriteLock knownItemLock = generation.getKnownItemLock();

    boolean removeUser = false;
    FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
    if (knownItemIDs != null) {

        Lock knownItemReadLock = knownItemLock.readLock();
        FastIDSet userKnownItemIDs;
        knownItemReadLock.lock();
        try {
            userKnownItemIDs = knownItemIDs.get(userID);
        } finally {
            knownItemReadLock.unlock();
        }

        if (userKnownItemIDs == null) {
            // Doesn't exist? So ignore this request
            return;
        }

        synchronized (userKnownItemIDs) {
            if (!userKnownItemIDs.remove(itemID)) {
                // Item unknown, so ignore this request
                return;
            }
            removeUser = userKnownItemIDs.isEmpty();
        }
    }

    // We can proceed with the request

    FastByIDMap<float[]> X = generation.getX();

    ReadWriteLock xLock = generation.getXLock();

    if (removeUser) {

        Lock knownItemWriteLock = knownItemLock.writeLock();
        knownItemWriteLock.lock();
        try {
            knownItemIDs.remove(userID);
        } finally {
            knownItemWriteLock.unlock();
        }

        Lock xWriteLock = xLock.writeLock();
        xWriteLock.lock();
        try {
            X.remove(userID);
        } finally {
            xWriteLock.unlock();
        }

    }

}