com.google.inject.servlet.ServletScopes Java Examples

The following examples show how to use com.google.inject.servlet.ServletScopes. 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: DataBackupServiceImpl.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
@Transactional
@Override
public void createBackUp(DataBackup dataBackup) {
  DataBackup obj = dataBackupRepository.find(dataBackup.getId());
  obj.setStatusSelect(DataBackupRepository.DATA_BACKUP_STATUS_IN_PROGRESS);
  dataBackupRepository.save(obj);
  if (dataBackup.getUpdateImportId()) {
    updateImportId();
  }
  try {
    executor.submit(
        new Callable<Boolean>() {
          @Override
          public Boolean call() throws Exception {
            RequestScoper scope = ServletScopes.scopeRequest(Collections.emptyMap());
            try (RequestScoper.CloseableScope ignored = scope.open()) {
              startBackup(obj);
            }
            return true;
          }
        });
  } catch (Exception e) {
    TraceBackService.trace(e);
  }
}
 
Example #2
Source File: GuiceScopingVisitor.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
public Class<? extends Annotation> visitScope(final Scope scope) {
    Class<? extends Annotation> res = null;
    if (scope == Scopes.SINGLETON) {
        res = javax.inject.Singleton.class;
    }
    if (scope == Scopes.NO_SCOPE) {
        res = Prototype.class;
    }
    if (scope == ServletScopes.REQUEST) {
        res = RequestScoped.class;
    }
    if (scope == ServletScopes.SESSION) {
        res = SessionScoped.class;
    }
    // not supporting custom scopes
    return res;
}
 
Example #3
Source File: ExtDirectJsonRequestProcessorThread.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public ExtDirectJsonRequestProcessorThread() {
  Subject subject = SecurityUtils.getSubject();
  checkState(subject != null, "Subject is not set");
  // create the thread state by this moment as this is created in the master (web container) thread
  threadState = new SubjectThreadState(subject);

  final String baseUrl = BaseUrlHolder.get();

  processRequest = ServletScopes.transferRequest(new Callable<String>()
  {
    @Override
    public String call() {
      threadState.bind();
      UserIdMdcHelper.set();
      try {
        // apply base-url from the original thread
        BaseUrlHolder.set(baseUrl);

        return ExtDirectJsonRequestProcessorThread.super.processRequest();
      }
      finally {
        UserIdMdcHelper.unset();
        threadState.restore();
      }

    }
  });
}
 
Example #4
Source File: ThreadedJob.java    From axelor-open-suite with GNU Affero General Public License v3.0 4 votes vote down vote up
private void executeInThreadedRequestScope(JobExecutionContext context) {
  RequestScoper scope = ServletScopes.scopeRequest(Collections.emptyMap());
  try (RequestScoper.CloseableScope ignored = scope.open()) {
    executeInThread(context);
  }
}