类javax.ejb.Lock源码实例Demo

下面列出了怎么用javax.ejb.Lock的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jaxrs-hypermedia   文件: OrderStore.java
@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;
}
 
源代码2 项目: jaxrs-hypermedia   文件: OrderStore.java
@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;
}
 
源代码3 项目: fido2   文件: MDS.java
@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;
}
 
@GET
@Lock(READ)
@Produces(MediaType.SERVER_SENT_EVENTS)
public void itemEvents(@HeaderParam(HttpHeaders.LAST_EVENT_ID_HEADER)
                       @DefaultValue("-1") int lastEventId,
                       @Context SseEventSink eventSink) {

    if (lastEventId >= 0)
        replayLastMessages(lastEventId, eventSink);

    sseBroadcaster.register(eventSink);
}
 
@Lock(WRITE)
public void onEvent(@Observes DomainEvent domainEvent) {
    String message = domainEvent.getContents();
    messages.add(message);

    OutboundSseEvent event = createEvent(message, ++lastEventId);

    sseBroadcaster.broadcast(event);
}
 
源代码6 项目: eplmp   文件: IndexerClientProducer.java
@Lock(LockType.READ)
@Produces
@ApplicationScoped
public JestClient produce() {
    LOGGER.log(Level.INFO, "Producing ElasticSearch rest client");
    return client;
}
 
源代码7 项目: jaxrs-hypermedia   文件: ShoppingCart.java
@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++);
    }
}
 
源代码8 项目: jaxrs-hypermedia   文件: ShoppingCart.java
@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);
}
 
源代码9 项目: jaxrs-hypermedia   文件: OrderStore.java
@Lock(LockType.READ)
public List<Order> getOrders() {
    final ArrayList<Order> orders = new ArrayList<>(this.orders.values());
    orders.sort(Comparator.comparing(Order::getId));

    return orders;
}
 
源代码10 项目: jaxrs-hypermedia   文件: ShoppingCart.java
@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++);
    }
}
 
源代码11 项目: jaxrs-hypermedia   文件: ShoppingCart.java
@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);
}
 
源代码12 项目: jaxrs-hypermedia   文件: OrderStore.java
@Lock(LockType.READ)
public List<Order> getOrders() {
    final ArrayList<Order> orders = new ArrayList<>(this.orders.values());
    orders.sort(Comparator.comparing(Order::getId));

    return orders;
}
 
源代码13 项目: jaxrs-hypermedia   文件: ShoppingCart.java
@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++);
    }
}
 
源代码14 项目: jaxrs-hypermedia   文件: ShoppingCart.java
@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);
}
 
源代码15 项目: jaxrs-hypermedia   文件: OrderStore.java
@Lock(LockType.READ)
public List<Order> getOrders() {
    final ArrayList<Order> orders = new ArrayList<>(this.orders.values());
    orders.sort(Comparator.comparing(Order::getId));

    return orders;
}
 
源代码16 项目: development   文件: ConfigurationServiceBean.java
@Schedule(minute = "*/10")
@Lock(LockType.WRITE)
public void refreshCache() {
    cache = new HashMap<>();
    for (ConfigurationSetting configurationSetting : getAllConfigurationSettings()) {
        addToCache(configurationSetting);
    }
}
 
源代码17 项目: development   文件: ConfigurationServiceBean.java
@Override
@Lock(LockType.WRITE)
public void setConfigurationSetting(String informationId, String value) {
    ConfigurationSetting configSetting = new ConfigurationSetting(
            ConfigurationKey.valueOf(informationId),
            Configuration.GLOBAL_CONTEXT, value);
    setConfigurationSetting(configSetting);
}
 
源代码18 项目: training   文件: ReadersWritersSingleton.java
@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());
}
 
源代码19 项目: training   文件: ReadersWritersSingleton.java
@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());
}
 
源代码20 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(WRITE)
public void buyTicket(int seatId) throws SeatBookedException, NoSuchSeatException {
    final Seat seat = getSeat(seatId);
    if (seat.isBooked()) {
        throw new SeatBookedException("Seat " + seatId + " already booked!");
    }
    addSeat(seat.getBookedSeat());
}
 
源代码21 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(READ)
private Seat getSeat(int seatId) throws NoSuchSeatException {
    final Seat seat = seats.get(seatId);
    if (seat == null) {
        throw new NoSuchSeatException("Seat " + seatId + " does not exist!");
    }
    return seat;
}
 
源代码22 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(WRITE)
public void buyTicket(int seatId) {
    final Seat seat = getSeat(seatId);
    if (seat.isBooked()) {
        throw new IllegalArgumentException("Seat is already booked: " + seatId);
    }
    final Seat bookedSeat = seat.getBookedSeat();
    addSeat(bookedSeat);

    seatEvent.fire(bookedSeat);
}
 
源代码23 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(WRITE)
public void buyTicket(int seatId) {
    final Seat seat = getSeat(seatId);
    if (seat.isBooked()) {
        throw new IllegalArgumentException("Seat is already booked: " + seatId);
    }
    final Seat bookedSeat = seat.getBookedSeat();
    addSeat(bookedSeat);

    seatEvent.fire(bookedSeat);
}
 
源代码24 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(WRITE)
public void buyTicket(int seatId) {
    final Seat seat = getSeat(seatId);
    if (seat.isBooked()) {
        throw new IllegalArgumentException("Seat is already booked: " + seatId);
    }
    final Seat bookedSeat = seat.getBookedSeat();
    addSeat(bookedSeat);

    seatEvent.fire(bookedSeat);
}
 
源代码25 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(READ)
private Seat getSeat(int seatId) throws NoSuchSeatException {
    final Seat seat = seats.get(seatId);
    if (seat == null) {
        throw new NoSuchSeatException("Seat " + seatId + " does not exist!");
    }
    return seat;
}
 
源代码26 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(WRITE)
public void buyTicket(int seatId) {
    final Seat seat = getSeat(seatId);
    final Seat bookedSeat = seat.getBookedSeat();
    addSeat(bookedSeat);

    seatEvent.fire(bookedSeat);
}
 
源代码27 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(WRITE)
public void buyTicket(int seatId) {
    final Seat seat = getSeat(seatId);
    final Seat bookedSeat = seat.getBookedSeat();
    addSeat(bookedSeat);

    seatEvent.fire(bookedSeat);
}
 
源代码28 项目: packt-java-ee-7-code-samples   文件: TheatreBox.java
@Lock(WRITE)
public void buyTicket(int seatId) {
    final Seat seat = getSeat(seatId);
    if (seat.isBooked()) {
        throw new IllegalArgumentException("Seat is already booked: " + seatId);
    }
    final Seat bookedSeat = seat.getBookedSeat();
    addSeat(bookedSeat);

    seatEvent.fire(bookedSeat);
}
 
源代码29 项目: fido2   文件: MDS.java
@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();
}
 
@Lock(LockType.WRITE)
public void remove(Session session) {
    sessions.remove(session);
}