本文整理匯總了Java中javax.ejb.Lock類的典型用法代碼示例。如果您正苦於以下問題:Java Lock類的具體用法?Java Lock怎麽用?Java Lock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Lock類屬於javax.ejb包,在下文中一共展示了Lock類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkout
import javax.ejb.Lock; //導入依賴的package包/類
@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: wasAnalyzed
import javax.ejb.Lock; //導入依賴的package包/類
@Override
@Lock(LockType.READ)
public boolean wasAnalyzed(HashId hashId) throws FileStoreException {
try (PreparedStatement preparedStatement = connection.prepareStatement(
"SELECT successful FROM " + HBaseElementNames.ANALYSIS_ANALYSES_TABLE + " WHERE hashid=?")) {
preparedStatement.setString(1, hashId.toString());
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (!resultSet.next()) {
return false;
}
boolean analyzed = resultSet.getBoolean(1);
if (resultSet.next()) {
throw new FileStoreException(
"Could not check for successful analysis due to multiple restuls for '" + hashId + "'.");
}
return analyzed;
}
} catch (SQLException e) {
throw new FileStoreException("Could not read analysis status.", e);
}
}
示例3: refreshCache
import javax.ejb.Lock; //導入依賴的package包/類
@Schedule(minute = "*/10")
@Lock(LockType.WRITE)
public void refreshCache() {
cache = new HashMap<>();
for (ConfigurationSetting configurationSetting : getAllConfigurationSettings()) {
addToCache(configurationSetting);
}
}
示例4: setConfigurationSetting
import javax.ejb.Lock; //導入依賴的package包/類
@Override
@Lock(LockType.WRITE)
public void setConfigurationSetting(String informationId, String value) {
ConfigurationSetting configSetting = new ConfigurationSetting(
ConfigurationKey.valueOf(informationId),
Configuration.GLOBAL_CONTEXT, value);
setConfigurationSetting(configSetting);
}
示例5: runTasks
import javax.ejb.Lock; //導入依賴的package包/類
@Lock(LockType.WRITE)
public void runTasks() {
if (!busy) {
busy = true;
try {
if (taskAppService.getRunningFlag()) {
queueTasks();
}
checkThreads();
} finally {
busy = false;
}
}
}
示例6: itemEvents
import javax.ejb.Lock; //導入依賴的package包/類
@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);
}
開發者ID:PacktPublishing,項目名稱:Architecting-Modern-Java-EE-Applications,代碼行數:13,代碼來源:EventsResource.java
示例7: onEvent
import javax.ejb.Lock; //導入依賴的package包/類
@Lock(WRITE)
public void onEvent(@Observes DomainEvent domainEvent) {
String message = domainEvent.getContents();
messages.add(message);
OutboundSseEvent event = createEvent(message, ++lastEventId);
sseBroadcaster.broadcast(event);
}
開發者ID:PacktPublishing,項目名稱:Architecting-Modern-Java-EE-Applications,代碼行數:10,代碼來源:EventsResource.java
示例8: produce
import javax.ejb.Lock; //導入依賴的package包/類
@Lock(LockType.READ)
@Produces
@ApplicationScoped
public JestClient produce() {
LOGGER.log(Level.INFO, "Producing ElasticSearch rest client");
return client;
}
示例9: addBookSelection
import javax.ejb.Lock; //導入依賴的package包/類
@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++);
}
}
示例10: updateBookSelection
import javax.ejb.Lock; //導入依賴的package包/類
@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);
}
示例11: getOrders
import javax.ejb.Lock; //導入依賴的package包/類
@Lock(LockType.READ)
public List<Order> getOrders() {
final ArrayList<Order> orders = new ArrayList<>(this.orders.values());
orders.sort(Comparator.comparing(Order::getId));
return orders;
}
示例12: registerService
import javax.ejb.Lock; //導入依賴的package包/類
@Override
@Lock(LockType.WRITE)
public void registerService(PluginInformation pluginInformation, String jndiName,
EvaluatorServiceInformation serviceInformation) {
super.registerService(pluginInformation, jndiName, serviceInformation);
addInformationToDatabase(pluginInformation, serviceInformation);
}
示例13: createProxy
import javax.ejb.Lock; //導入依賴的package包/類
@Override
@Lock(LockType.READ)
public Evaluator createProxy(String jndi) {
Evaluator evaluator = JndiUtils.createRemoteEJBInstance(Evaluator.class, jndi);
EvaluatorInformation information = evaluator.getInformation();
for (ConfigurationParameter<?> configurationParameter : evaluator.getConfigurationParameters()) {
PreferencesValue<?> value = preferencesStore.getPluginDefaultPreference(information.getId(),
configurationParameter);
if (value != null) {
evaluator.setConfigurationParameter(configurationParameter, value.getValue());
}
}
return evaluator;
}
示例14: getEvaluatorPluginInformation
import javax.ejb.Lock; //導入依賴的package包/類
@Override
@Lock(LockType.READ)
public EvaluatorServiceInformation getEvaluatorPluginInformation(String evaluatorId) {
for (EvaluatorServiceInformation evaluator : getServices()) {
if (evaluator.getId().equals(evaluatorId)) {
return evaluator;
}
}
return null;
}
示例15: createProxy
import javax.ejb.Lock; //導入依賴的package包/類
@Override
@Lock(LockType.READ)
public Repository createProxy(String jndi) {
Repository repository = JndiUtils.createRemoteEJBInstance(Repository.class, jndi);
String repositoryName = repository.getName();
RepositoryServiceInformation information = findByName(repositoryName);
for (ConfigurationParameter<?> configurationParameter : repository.getConfigurationParameters()) {
PreferencesValue<?> value = preferencesStore.getPluginDefaultPreference(information.getId(),
configurationParameter);
if (value != null) {
repository.setConfigurationParameter(configurationParameter, value.getValue());
}
}
return repository;
}