2013-11-21 5 views
1

JackRabbit 저장소를 찾아야합니다. 다음 코드를 사용하여 연결합니다 :Java의 jackrabbit 저장소에 연결 시간 제한을 설정하는 방법

Repository repository = JcrUtils.getRepository(url); 
SimpleCredentials credentials = new SimpleCredentials(user, password.toCharArray()); 
session = repository.login(credentials, workspace); 

그러나 어떤 이유로 일부 매개 변수가 잘못된 경우 웹 응용 프로그램이 작동하지 않습니다. 내가 뭘 해야하는지 (예 : 30 초) 시간 제한 연결을 설정하지만 jcr API에서 어떤 방법을 찾을 수 없습니다.
어떻게 할 수 있는지에 대한 조언이나 코드 샘플이 있습니까?

PS : 사용하는 jackrabbit의 버전은 2.2.10입니다.

답변

1

그래서 FutureTask을 사용하여 연결 제한 시간을 추가 할 수있었습니다.
나는 Callable 인터페이스를 구현하는 클래스를 만들었와 call() 방법 나는 연결 논리를 넣어 :

public class CallableSession implements Callable<Session> { 

private final String url; 
private final String user; 
private final String password; 
private final String workspace; 

public CallableSession(String url, String user, String password, String workspace) { 
    this.url = url; 
    this.user = user; 
    this.password = password; 
    this.workspace = workspace; 
} 

@Override 
public Session call() throws Exception { 

    Repository repository = JcrUtils.getRepository(url); 
    SimpleCredentials credentials = new SimpleCredentials(user, password.toCharArray()); 
    Session session = repository.login(credentials, workspace); 

    return session; 
} 
다음, 나는 FutureTask을 만들어 getSession() 함수 내에서 내 커넥터 클래스에서, 그것을 실행 넣어

거기 연결 시간 초과 :

public Session getSession() { 

    if (session == null) { 
     try { 
      CallableSession cs = new CallableSession(url, user, password, workspace); 
      FutureTask<Session> future = new FutureTask<Session>(cs); 
      ExecutorService executor = Executors.newSingleThreadExecutor(); 
      executor.execute(future); 
      session = future.get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); 

     } catch (InterruptedException ex) { 
      Logger.getLogger(JackRabbitConnector.class.getName()).log(Level.SEVERE, null, ex); 
     } catch (ExecutionException ex) { 
      Logger.getLogger(JackRabbitConnector.class.getName()).log(Level.SEVERE, null, ex); 
     } catch (TimeoutException ex) { 
      Logger.getLogger(JackRabbitConnector.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 
    return session; 
} 
관련 문제