Search in sources :

Example 1 with Lock

use of javax.ejb.Lock in project Payara by payara.

the class LockHandler method postProcessAnnotation.

/**
 * Set the default value (from class type annotation) on all
 * methods that don't have a value.
 */
public void postProcessAnnotation(AnnotationInfo ainfo, EjbContext ejbContext) throws AnnotationProcessorException {
    EjbSessionDescriptor ejbDesc = (EjbSessionDescriptor) ejbContext.getDescriptor();
    Class classAn = (Class) ainfo.getAnnotatedElement();
    Lock lockAnn = (Lock) ainfo.getAnnotation();
    // At this point, all method-level specific annotations have been processed.
    // For non-private methods, find the ones from the EjbContext's
    // component definition view that are declared on this class.  This will correctly
    // eliminate any overridden methods and provide the most-derived version of each.
    // Use the Class's declared methods list to get the private methods.
    List<Method> toProcess = new ArrayList<Method>();
    for (Method m : ejbContext.getComponentDefinitionMethods()) {
        if (classAn.equals(m.getDeclaringClass())) {
            toProcess.add(m);
        }
    }
    for (Method m : classAn.getDeclaredMethods()) {
        if (Modifier.isPrivate(m.getModifiers())) {
            toProcess.add(m);
        }
    }
    for (Method m : toProcess) {
        // descriptor, set it.
        if (!matchesExistingReadOrWriteLockMethod(m, ejbDesc)) {
            MethodDescriptor newMethodDesc = new MethodDescriptor(m);
            if (lockAnn.value() == LockType.WRITE) {
                ejbDesc.addWriteLockMethod(newMethodDesc);
            } else {
                ejbDesc.addReadLockMethod(newMethodDesc);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) Lock(javax.ejb.Lock)

Example 2 with Lock

use of javax.ejb.Lock in project muikku by otavanopisto.

the class MaterialUnEmbedder method unembedWorkspaceMaterials.

@Lock
public void unembedWorkspaceMaterials(WorkspaceNode parentNode) throws DeusNexInternalException {
    try {
        loadHtmlMaterialPieces();
        for (WorkspaceNode node : workspaceMaterialController.listWorkspaceNodesByParent(parentNode)) {
            unembedWorkspaceNode(parentNode, node);
        }
        saveHtmlMaterialPieces();
    } catch (XPathExpressionException | SAXException | IOException | ParserConfigurationException | TransformerException | WorkspaceMaterialContainsAnswersExeption e) {
        throw new DeusNexInternalException(e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException) Lock(javax.ejb.Lock)

Example 3 with Lock

use of javax.ejb.Lock in project solr-document-store by DBCDK.

the class SolrIndexer method unitFor.

@Lock(LockType.READ)
public String unitFor(String pid) throws RepositoryException {
    try (IRepositoryDAO dao = daoProvider.getRepository()) {
        IRepositoryIdentifier id = dao.createIdentifier(pid);
        if (!dao.hasObject(id)) {
            throw new IllegalStateException("Doesn't have pid: " + pid);
        }
        if (dao.getObjectState(id) == IRepositoryDAO.State.DELETED) {
            return null;
        }
        ISysRelationsStream relations = dao.getSysRelationsStream(id);
        IRepositoryIdentifier unit = relations.getUnitFor();
        return unit.toString();
    }
}
Also used : ISysRelationsStream(dk.dbc.opensearch.commons.repository.ISysRelationsStream) IRepositoryIdentifier(dk.dbc.opensearch.commons.repository.IRepositoryIdentifier) IRepositoryDAO(dk.dbc.opensearch.commons.repository.IRepositoryDAO) Lock(javax.ejb.Lock)

Example 4 with Lock

use of javax.ejb.Lock in project solr-document-store by DBCDK.

the class SolrIndexer method buildDocuments.

@Lock(LockType.READ)
@SuppressFBWarnings(value = "ICAST_IDIV_CAST_TO_DOUBLE", justification = "trimming of number of digits for LogStash.Marker#append()")
public void buildDocuments(String pid, SolrIndexerJS jsWrapper, BiConsumer<String, SolrUpdaterCallback> function) throws Exception {
    try (IRepositoryDAO dao = daoProvider.getRepository()) {
        if (jsWrapper.isIndexableIdentifier(pid)) {
            long starttime = System.nanoTime();
            String trackingId = getTrackingId(dao, pid);
            DBCTrackedLogContext.setTrackingId(trackingId);
            String data = getObjectData(dao, pid);
            SolrUpdaterCallback callback = new SolrUpdaterCallback(jsWrapper.getEnvironment(), trackingId, pid);
            jsWrapper.createIndexData(dao, pid, data, callback, libraryRuleHandler);
            documentsDeleted.inc(callback.getDeletedDocumentsCount());
            documentsUpdated.inc(callback.getUpdatedDocumentsCount());
            if (callback.getDeletedDocumentsCount() > 0 || callback.getUpdatedDocumentsCount() > 0) {
                function.accept(data, callback);
            } else {
                log.info("Indexing {} skipped by javascript", pid);
            }
            long endtime = System.nanoTime();
            log.info(LogAppender.getMarker(App.APP_NAME, pid, LogAppender.SUCCEDED).and(append("duration", ((endtime - starttime) / 10000L) / 100.0)).and(append("updates", callback.getUpdatedDocumentsCount())).and(append("deletes", callback.getDeletedDocumentsCount())), "Documents successfully build");
        } else {
            log.debug("object {} filtered", pid);
        }
    } catch (Exception ex) {
        String error = String.format("Error calling indexing logic for '%s'", pid);
        log.error(LogAppender.getMarker(App.APP_NAME, pid, LogAppender.FAILED), error);
        throw ex;
    } finally {
        DBCTrackedLogContext.remove();
    }
}
Also used : IRepositoryDAO(dk.dbc.opensearch.commons.repository.IRepositoryDAO) RepositoryException(dk.dbc.opensearch.commons.repository.RepositoryException) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) EJBException(javax.ejb.EJBException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Lock(javax.ejb.Lock)

Example 5 with Lock

use of javax.ejb.Lock in project tomee by apache.

the class BeanContext method initDefaultLock.

private void initDefaultLock() {
    if (!BeanType.SINGLETON.equals(this.componentType)) {
        return;
    }
    final ArrayList<Class> classes = new ArrayList<>();
    classes.addAll(businessRemotes);
    classes.addAll(businessLocals);
    classes.add(this.beanClass);
    for (final Class c : classes) {
        Lock lock = null;
        try {
            lock = (Lock) c.getAnnotation(Lock.class);
            this.getSingleton().lockType = lock.value();
            if (logger.isDebugEnabled()) {
                logger.debug("Declared Lock for " + c.getName() + " is " + this.getSingleton().lockType);
            }
        } catch (final NullPointerException e) {
        // Ignore
        } catch (final Throwable e) {
            logger.warning("Failed to determine from: " + lock);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Default Lock for " + this.beanClass.getName() + " is " + this.getSingleton().lockType);
    }
}
Also used : ArrayList(java.util.ArrayList) Lock(javax.ejb.Lock)

Aggregations

Lock (javax.ejb.Lock)8 IRepositoryDAO (dk.dbc.opensearch.commons.repository.IRepositoryDAO)3 ArrayList (java.util.ArrayList)3 IRepositoryIdentifier (dk.dbc.opensearch.commons.repository.IRepositoryIdentifier)2 ISysRelationsStream (dk.dbc.opensearch.commons.repository.ISysRelationsStream)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)1 RepositoryException (dk.dbc.opensearch.commons.repository.RepositoryException)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 MailAttachment (fi.otavanopisto.muikku.mail.MailAttachment)1 MailType (fi.otavanopisto.muikku.mail.MailType)1 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)1 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)1 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 DeusNexInternalException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException)1 WorkspaceMaterialContainsAnswersExeption (fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption)1 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 ContactType (fi.otavanopisto.pyramus.rest.model.ContactType)1