Java Code Examples for javax.ejb.LockType#READ

The following examples show how to use javax.ejb.LockType#READ . 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: WorkerBean.java    From tutorials with MIT License 6 votes vote down vote up
@Lock(LockType.READ)
public void doTimerWork() throws InterruptedException {

    System.out.println("Timer method called but not started yet !");

    if (!busy.compareAndSet(false, true)) {
        return;
    }

    try {
        System.out.println("Timer work started");
        Thread.sleep(12000);
        System.out.println("Timer work done");
    } finally {
        busy.set(false);
    }
}
 
Example 2
Source File: SyncEventStoreCommitNotifier.java    From JEEventStore with MIT License 5 votes vote down vote up
@Override
@Lock(LockType.READ)
public void notifyListeners(ChangeSet changeSet) {
    if (changeSet == null)
        throw new IllegalArgumentException("changeSet must not be null");
    this.performNotification(changeSet);
}
 
Example 3
Source File: OrderStore.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.READ)
public List<Order> getOrders() {
    final ArrayList<Order> orders = new ArrayList<>(this.orders.values());
    orders.sort(Comparator.comparing(Order::getId));

    return orders;
}
 
Example 4
Source File: EventSerializerGson.java    From JEEventStore with MIT License 5 votes vote down vote up
@Override
@Lock(LockType.READ)
public String serialize(List<? extends Serializable> events) {
    if (events == null)
        throw new IllegalArgumentException("events must not be null");
    EventList evlist = new EventList(events);
    return gson.toJson(evlist);
}
 
Example 5
Source File: EventSerializerGson.java    From JEEventStore with MIT License 5 votes vote down vote up
@Override
@Lock(LockType.READ)
public List<? extends Serializable> deserialize(String body) {
    if (body == null)
        throw new IllegalArgumentException("body must not be null");
    log.log(Level.FINER, "deserializing body: " + body);
    return this.gson.fromJson(body, EventList.class).events();
}
 
Example 6
Source File: ReadersWritersSingleton.java    From training with MIT License 5 votes vote down vote up
@Lock(LockType.READ)
public void readerMethod(int threadId) {
	System.out.println("Enter READER " + threadId + ". R:" + readerCount.incrementAndGet() + "/w:"
			+ writerCount.get());
	try {
		Thread.sleep(300);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	System.out.println("Exit READER " + threadId + ". R:" + readerCount.decrementAndGet() + "/w:"
			+ writerCount.get());
}
 
Example 7
Source File: OrderStore.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.READ)
public Order getOrder(long id) {
    return orders.get(id);
}
 
Example 8
Source File: SingletonExample02.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Lock(LockType.READ) //override default: allow concurrent access
@Override
public void incrementCounter() {
    x = x + 1;
}
 
Example 9
Source File: SessionRegistry.java    From packt-java-ee-7-code-samples with GNU General Public License v2.0 4 votes vote down vote up
@Lock(LockType.READ)
public Set<Session> getAll() {
    return Collections.unmodifiableSet(sessions);
}
 
Example 10
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.READ)
public Set<BookSelection> getSelections() {
    return Collections.unmodifiableSet(selections);
}
 
Example 11
Source File: OrderStore.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.READ)
public Order getOrder(long id) {
    return orders.get(id);
}
 
Example 12
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.READ)
public BookSelection getSelection(long selectionId) {
    return selections.stream()
            .filter(s -> s.getId() == selectionId).findAny()
            .orElse(null);
}
 
Example 13
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.READ)
public Set<BookSelection> getSelections() {
    return Collections.unmodifiableSet(selections);
}
 
Example 14
Source File: MDS.java    From fido2 with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@Lock(LockType.READ)
public JsonObject getTrustAnchors(String aaguid, List<String> allowedStatusList) {
    JsonObjectBuilder ret = Json.createObjectBuilder();
    JsonArrayBuilder errors = Json.createArrayBuilder();
    JsonObjectBuilder error = Json.createObjectBuilder();
    MetadataTOCPayloadEntry entry = null;
    MetadataStatement st = null;

    for (MDSService service : mdsList) {
        entry = service.getTOCEntry(aaguid);
        if (entry!=null) {
            for (StatusReport status : entry.getStatusReports()) {
                if (status.getStatus()==AuthenticatorStatus.ATTESTATION_KEY_COMPROMISE ||
                        status.getStatus()==AuthenticatorStatus.REVOKED ||
                        status.getStatus()==AuthenticatorStatus.USER_KEY_PHYSICAL_COMPROMISE ||
                        status.getStatus()==AuthenticatorStatus.USER_KEY_REMOTE_COMPROMISE ||
                        status.getStatus()==AuthenticatorStatus.USER_VERIFICATION_BYPASS
                        ) {
                    error.add("message", "Authenticator status = "+status.getStatus().name());
                    errors.add(error);
                }
                else if(!allowedStatusList.contains(status.getStatus().name())){
                    error.add("message", "Authenticator status = " + status.getStatus().name() + "not allowed by policy");
                    errors.add(error);
                }
            }
        }

        st = service.getMetadataStatement(aaguid);
        if (st != null) {
            List<String> attestationRootCertificates = st.getAttestationRootCertificates();
            if (attestationRootCertificates != null) {
                JsonArrayBuilder certs = Json.createArrayBuilder();
                for (String c : attestationRootCertificates) {
                    certs.add(c);
                    System.out.println("Certificate found : " + c);
                }

                ret.add("attestationRootCertificates", certs);
            }

            List<EcdaaTrustAnchor> ecdaaTrustAnchors = st.getEcdaaTrustAnchors();
            if (ecdaaTrustAnchors != null) {
                JsonArrayBuilder trustAnchors = Json.createArrayBuilder();
                for (EcdaaTrustAnchor t : ecdaaTrustAnchors) {
                    try {
                        trustAnchors.add(objectMapper.writeValueAsString(t));
                    } catch (JsonProcessingException ex) {
                        Logger.getLogger(MDS.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                ret.add("ecdaaTrustAnchors", trustAnchors);
            }
            break;
        }
    }
    if (entry==null && st==null) {
        error.add("message", "Could not find metadata for aaguid "+aaguid);
        errors.add(error);
    }
    ret.add("errors", errors);
    return ret.build();
}
 
Example 15
Source File: SimplePersistenceContextProvider.java    From JEEventStore with MIT License 4 votes vote down vote up
@Override
@Lock(LockType.READ)
public EntityManager entityManagerForWriting(String bucketId) {
    return entityManager;
}
 
Example 16
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.READ)
public BookSelection getSelection(final long selectionId) {
    return selections.stream().filter(s -> s.getId() == selectionId).findFirst().orElse(null);
}
 
Example 17
Source File: CarStorage.java    From Architecting-Modern-Java-EE-Applications with MIT License 4 votes vote down vote up
@Lock(LockType.READ)
public Car retrieve(String id) {
    return cars.get(id);
}
 
Example 18
Source File: SingletonExample02.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Lock(LockType.READ) //override default: allow concurrent access
@Override
public void incrementCounter() {
    x = x + 1;
}
 
Example 19
Source File: UserMethodLevelBean.java    From javaee8-cookbook with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.READ)
public int getUserCount(){
    return userCount;
}
 
Example 20
Source File: SimplePersistenceContextProvider.java    From JEEventStore with MIT License 4 votes vote down vote up
@Override
@Lock(LockType.READ)
public EntityManager entityManagerForReading(String bucketId) {
    return entityManager;
}