javax.ejb.LockType Java Examples

The following examples show how to use javax.ejb.LockType. 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: OrderStore.java    From jaxrs-hypermedia with Apache License 2.0 6 votes vote down vote up
@Lock(LockType.WRITE)
public Order checkout() {
    final Order order = new Order();
    order.getSelections().addAll(shoppingCart.getSelections());
    order.setPrice(priceCalculator.calculateTotal(order.getSelections()));

    final long id = orders.size() + 1;
    order.setId(id);
    order.setDate(LocalDateTime.now());
    order.setStatus(OrderStatus.CONFIRMED);

    shoppingCart.clear();

    orders.put(id, order);
    return order;
}
 
Example #2
Source File: OrderStore.java    From jaxrs-hypermedia with Apache License 2.0 6 votes vote down vote up
@Lock(LockType.WRITE)
public Order checkout() {
    final Order order = new Order();
    order.getSelections().addAll(shoppingCart.getSelections());
    order.setPrice(priceCalculator.calculateTotal(order.getSelections()));

    final long id = orders.size() + 1;
    order.setId(id);
    order.setDate(LocalDateTime.now());
    order.setStatus(OrderStatus.CONFIRMED);

    shoppingCart.clear();

    orders.put(id, order);
    return order;
}
 
Example #3
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 #4
Source File: OrderStore.java    From jaxrs-hypermedia with Apache License 2.0 6 votes vote down vote up
@Lock(LockType.WRITE)
public Order checkout() {
    final Order order = new Order();
    order.getSelections().addAll(shoppingCart.getSelections());
    order.setPrice(priceCalculator.calculateTotal(order.getSelections()));

    final long id = orders.size() + 1;
    order.setId(id);
    order.setDate(LocalDateTime.now());
    order.setStatus(OrderStatus.CONFIRMED);

    shoppingCart.clear();

    orders.put(id, order);
    return order;
}
 
Example #5
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 #6
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void updateBookSelection(long selectionId, int quantity) {
    final BookSelection selection = selections.stream()
            .filter(s -> s.getId() == selectionId).findFirst()
            .orElseThrow(() -> new IllegalArgumentException("No selection found"));

    selection.setQuantity(quantity);
    updatePrice(selection);

    if (quantity == 0)
        selections.remove(selection);
}
 
Example #7
Source File: ReadersWritersSingleton.java    From training with MIT License 5 votes vote down vote up
@Lock(LockType.WRITE)
public void writerMethod(int threadId) {
	System.out.println("Entering WRITER " + threadId + ". R:" + readerCount.get() + "/w:"
			+ writerCount.incrementAndGet());
	try {
		Thread.sleep(300);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	System.out.println("Exiting WRITER " + threadId + ". R:" + readerCount.get() + "/w:"
			+ writerCount.decrementAndGet());
}
 
Example #8
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 #9
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 #10
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void addBookSelection(BookSelection selection) {
    final Optional<BookSelection> existentSelection = selections.stream().filter(s -> s.getBook().equals(selection.getBook())).findFirst();

    if (existentSelection.isPresent()) {
        final BookSelection bookSelection = existentSelection.get();
        bookSelection.setQuantity(bookSelection.getQuantity() + selection.getQuantity());
        updatePrice(bookSelection);
    } else {
        updatePrice(selection);
        selections.add(selection);
        selection.setId(nextSelectionId++);
    }
}
 
Example #11
Source File: IndexerClientProducer.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@Lock(LockType.READ)
@Produces
@ApplicationScoped
public JestClient produce() {
    LOGGER.log(Level.INFO, "Producing ElasticSearch rest client");
    return client;
}
 
Example #12
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 #13
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 #14
Source File: AbstractEventStoreCommitNotifier.java    From JEEventStore with MIT License 5 votes vote down vote up
@Override
@Lock(LockType.WRITE)
public void addListener(String bucketId, EventStoreCommitListener listener) {
    if (listener == null)
        throw new IllegalArgumentException("listener must not be null");
    List<EventStoreCommitListener> list = listFor(bucketId, true);
    if (list.contains(listener))
        throw new IllegalStateException("Listener already listening.");
    list.add(listener);
}
 
Example #15
Source File: AbstractEventStoreCommitNotifier.java    From JEEventStore with MIT License 5 votes vote down vote up
@Override
@Lock(LockType.WRITE)
public void removeListener(String bucketId, EventStoreCommitListener listener) {
    if (listener == null)
        throw new IllegalArgumentException("listener must not be null");
    List<EventStoreCommitListener> list = listFor(bucketId, false);
    if (list == null || !list.contains(listener))
        throw new IllegalStateException("Listener not found.");
    list.remove(listener);
}
 
Example #16
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 #17
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void addBookSelection(BookSelection selection) {
    final Optional<BookSelection> existentSelection = selections.stream().filter(s -> s.getBook().equals(selection.getBook())).findFirst();

    if (existentSelection.isPresent()) {
        final BookSelection bookSelection = existentSelection.get();
        bookSelection.setQuantity(bookSelection.getQuantity() + selection.getQuantity());
        updatePrice(bookSelection);
    } else {
        updatePrice(selection);
        selections.add(selection);
        selection.setId(nextSelectionId++);
    }
}
 
Example #18
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void updateBookSelection(long selectionId, int quantity) {
    final BookSelection selection = selections.stream()
            .filter(s -> s.getId() == selectionId).findFirst()
            .orElseThrow(() -> new IllegalArgumentException("No selection found"));

    selection.setQuantity(quantity);
    updatePrice(selection);

    if (quantity == 0)
        selections.remove(selection);
}
 
Example #19
Source File: TransactionRegistryInTimeoutTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Timeout
@Lock(LockType.WRITE)
public void timerFired() {
    try {
        final String jndi = "java:comp/TransactionSynchronizationRegistry";
        final TransactionSynchronizationRegistry txRegistry = (TransactionSynchronizationRegistry) new InitialContext().lookup(jndi);
        assertNotNull(txRegistry);
        assertNotNull(context.lookup(jndi));
        assertNotNull(registry);
        txRegistry.registerInterposedSynchronization(sync);
    } catch (final NamingException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #20
Source File: ConfigurationServiceBean.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
@Lock(LockType.WRITE)
public void setConfigurationSetting(String informationId, String value) {
    ConfigurationSetting configSetting = new ConfigurationSetting(
            ConfigurationKey.valueOf(informationId),
            Configuration.GLOBAL_CONTEXT, value);
    setConfigurationSetting(configSetting);
}
 
Example #21
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 #22
Source File: ConfigurationServiceBean.java    From development with Apache License 2.0 5 votes vote down vote up
@Schedule(minute = "*/10")
@Lock(LockType.WRITE)
public void refreshCache() {
    cache = new HashMap<>();
    for (ConfigurationSetting configurationSetting : getAllConfigurationSettings()) {
        addToCache(configurationSetting);
    }
}
 
Example #23
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void addBookSelection(BookSelection selection) {
    final Optional<BookSelection> existentSelection = selections.stream().filter(s -> s.getBook().equals(selection.getBook())).findFirst();

    if (existentSelection.isPresent()) {
        final BookSelection bookSelection = existentSelection.get();
        bookSelection.setQuantity(bookSelection.getQuantity() + selection.getQuantity());
        updatePrice(bookSelection);
    } else {
        updatePrice(selection);
        selections.add(selection);
        selection.setId(nextSelectionId++);
    }
}
 
Example #24
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void updateBookSelection(long selectionId, int quantity) {
    final BookSelection selection = selections.stream()
            .filter(s -> s.getId() == selectionId).findFirst()
            .orElseThrow(() -> new IllegalArgumentException("No selection found"));

    selection.setQuantity(quantity);
    updatePrice(selection);

    if (quantity == 0)
        selections.remove(selection);
}
 
Example #25
Source File: MDS.java    From fido2 with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Schedule(hour = "3")
@Lock(LockType.WRITE)
private void refresh() {
    List<MDSService> newList = new ArrayList<>();

    for (MDSService service : mdsList) {
        try {
            service.refresh();
            newList.add(service);
        } catch (Exception e) {
            // if there's an exception, it won't get added to the new list
        }
    }
    mdsList = newList;
}
 
Example #26
Source File: CountryStateContainerManagedBean.java    From tutorials with MIT License 5 votes vote down vote up
@Lock(LockType.WRITE)
@PostConstruct
public void initialize() {

    List<String> states = new ArrayList<String>();
    states.add("Texas");
    states.add("Alabama");
    states.add("Alaska");
    states.add("Arizona");
    states.add("Arkansas");

    countryStatesMap.put("UnitedStates", states);
}
 
Example #27
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.WRITE)
public void remove(Session session) {
    sessions.remove(session);
}
 
Example #28
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.WRITE)
public void add(Session session) {
    sessions.add(session);
}
 
Example #29
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 #30
Source File: MarketSummarySingleton.java    From sample.daytrader7 with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.READ)
public MarketSummaryDataBean getMarketSummaryDataBean() {       
    return marketSummaryDataBean;
}