@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; }
@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); } }
@Schedule(minute = "*/10") @Lock(LockType.WRITE) public void refreshCache() { cache = new HashMap<>(); for (ConfigurationSetting configurationSetting : getAllConfigurationSettings()) { addToCache(configurationSetting); } }
@Override @Lock(LockType.WRITE) public void setConfigurationSetting(String informationId, String value) { ConfigurationSetting configSetting = new ConfigurationSetting( ConfigurationKey.valueOf(informationId), Configuration.GLOBAL_CONTEXT, value); setConfigurationSetting(configSetting); }
@Lock(LockType.WRITE) public void runTasks() { if (!busy) { busy = true; try { if (taskAppService.getRunningFlag()) { queueTasks(); } checkThreads(); } finally { busy = false; } } }
@Lock(LockType.READ) @Produces @ApplicationScoped public JestClient produce() { LOGGER.log(Level.INFO, "Producing ElasticSearch rest client"); return client; }
@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++); } }
@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); }
@Lock(LockType.READ) public List<Order> getOrders() { final ArrayList<Order> orders = new ArrayList<>(this.orders.values()); orders.sort(Comparator.comparing(Order::getId)); return orders; }
@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; }
@Override @Lock(LockType.READ) public EvaluatorServiceInformation getEvaluatorPluginInformation(String evaluatorId) { for (EvaluatorServiceInformation evaluator : getServices()) { if (evaluator.getId().equals(evaluatorId)) { return evaluator; } } return null; }
@Override @Lock(LockType.READ) public boolean isActive(String evaluatorId) { Boolean active = analyzerActivations.get(evaluatorId); if (active != null) { return active; } active = preferencesStore.isServiceActive(evaluatorId); analyzerActivations.put(evaluatorId, active); return active; }
@Override @Lock(LockType.READ) public Evaluator getInstanceById(String evaluatorId) { for (EvaluatorServiceInformation evaluator : getServices()) { if (evaluator.getId().equals(evaluatorId)) { return createProxy(evaluator.getJndiName()); } } return null; }
@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; }
@Override @Lock(LockType.READ) public Repository getInstanceById(String analyzerId) { for (RepositoryServiceInformation repository : getServices()) { if (repository.getId().equals(analyzerId)) { return createProxy(repository.getJndiName()); } } return null; }
@Override @Lock(LockType.READ) public RepositoryLocation createFromSerialization(Properties repositoryLocation) { String repositoryId = repositoryLocation.getProperty(RepositoryManager.REPOSITORY_ID_PROPERTY); Repository instance = getInstanceById(repositoryId); return new RepositoryLocation() { private static final long serialVersionUID = 1084534331267078708L; @Override public List<SourceCodeLocation> getSourceCodes(FileSearchConfiguration fileSearchConfiguration) { return instance.getSourceCodes(repositoryLocation, fileSearchConfiguration); } @Override public Properties getSerialization() { return repositoryLocation; } @Override public String getName() { return instance.getName(); } @Override public String getHumanReadableLocationString() { return instance.getHumanReadableLocationString(repositoryLocation); } }; }
@Override @Lock(LockType.READ) public ProgrammingLanguageAnalyzer createProxy(String jndi) { ProgrammingLanguageAnalyzer analyzer = JndiUtils.createRemoteEJBInstance(ProgrammingLanguageAnalyzer.class, jndi); AnalyzerServiceInformation information = findByName(analyzer.getName(), analyzer.getVersion()); for (ConfigurationParameter<?> configurationParameter : analyzer.getConfigurationParameters()) { PreferencesValue<?> value = preferencesStore.getPluginDefaultPreference(information.getId(), configurationParameter); if (value != null) { analyzer.setConfigurationParameter(configurationParameter, value.getValue()); } } return analyzer; }
@Override @Lock(LockType.READ) public AnalyzerServiceInformation findByName(String languageName, String languageVersion) { for (AnalyzerServiceInformation analyzerServiceInformation : getServices()) { if (analyzerServiceInformation.getName().equals(languageName) && analyzerServiceInformation.getVersion().equals(languageVersion)) { return analyzerServiceInformation; } } return null; }
@Override @Lock(LockType.READ) public boolean isActive(String analyzerId) { Boolean active = analyzerActivations.get(analyzerId); if (active != null) { return active; } active = preferencesStore.isServiceActive(analyzerId); analyzerActivations.put(analyzerId, active); return active; }
@Override @Lock(LockType.READ) public ProgrammingLanguageAnalyzer getInstanceById(String analyzerId) { for (AnalyzerServiceInformation analyzer : getServices()) { if (analyzer.getId().equals(analyzerId)) { return createProxy(analyzer.getJndiName()); } } return null; }
@Override @Lock(LockType.READ) public InputStream readRawFile(HashId hashId) throws FileStoreException { try { return bloob.readRawFile(hashId); } catch (IOException e) { throw new FileStoreException(e); } }
@Override @Lock(LockType.WRITE) public void registerService(PluginInformation pluginInformation, String jndiName, ServiceInfo serviceInformation) { logger.info("Register new service '" + jndiName + "' from plugin '" + pluginInformation.getName() + "'."); services.put(jndiName, serviceInformation); plugins.put(jndiName, pluginInformation); logger.info("New service '" + jndiName + "' registered."); }
/** * This method returns a list of all plugins which provide services which * are registered already. * * @return A {@link Collection} of {@link PluginInformation} is returned. */ @Override @Lock(LockType.READ) public Collection<PluginInformation> getPlugins() { Set<PluginInformation> plugins = new HashSet<>(); plugins.addAll(this.plugins.values()); return plugins; }
@Schedule(minute = "*/10") @Lock(LockType.WRITE) public void refreshCache() { tenantSettings = getAllSettings(); }
@Override @TransactionAttribute(TransactionAttributeType.MANDATORY) @Lock(LockType.WRITE) public void setConfigurationSetting(ConfigurationSetting configSetting) { ConfigurationSetting setting = getConfigurationSettingExactMatch( configSetting.getInformationId(), configSetting.getContextId()); if (!isEmpty(configSetting.getValue())) { // check the type and trim the string if necessary String value = configSetting.getValue(); if (configSetting.getInformationId() .getType() == ConfigurationKey.TYPE_BOOLEAN || configSetting.getInformationId() .getType() == ConfigurationKey.TYPE_LONG || configSetting.getInformationId() .getType() == ConfigurationKey.TYPE_URL || configSetting.getInformationId() .getType() == ConfigurationKey.TYPE_STRING || configSetting.getInformationId() .getType() == ConfigurationKey.TYPE_PASSWORD) { value = value.trim(); } // if the value is not empty, update or create the setting if (setting != null) { // if entry is already present, update it setting.setValue(value); } else { // if not, create a new one try { configSetting.setValue(value); dm.persist(configSetting); } catch (NonUniqueBusinessKeyException e) { logger.logError(Log4jLogger.SYSTEM_LOG, e, LogMessageIdentifier.ERROR_PERSIST_CONFIGURATION_SETTING); } } } else { // remove optional empty settings so that the default value can be // used again if (setting != null) { dm.remove(setting); } } refreshCache(); }
@Lock(LockType.READ) @Override public void incrementCounter() { x = x + 1; }
@Lock(LockType.READ) public boolean isBusy() { return busy; }
@Lock(LockType.READ) public Car retrieve(String id) { return cars.get(id); }
@Lock(LockType.WRITE) public void clear() { selections.clear(); }
@Lock(LockType.READ) public Set<BookSelection> getSelections() { return Collections.unmodifiableSet(selections); }
@Lock(LockType.READ) public BookSelection getSelection(final long selectionId) { return selections.stream().filter(s -> s.getId() == selectionId).findFirst().orElse(null); }
@Lock(LockType.READ) public Order getOrder(long id) { return orders.get(id); }