001/* 002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.api; 020 021import java.util.List; 022 023/** 024 * Service managing the acquisition/release of {@link CoreSession} instances. 025 * 026 * @since 8.4 027 */ 028public interface CoreSessionService { 029 030 /** 031 * Debug information about a {@link CoreSession} acquisition. 032 */ 033 static class CoreSessionRegistrationInfo extends Throwable { 034 035 private static final long serialVersionUID = 1L; 036 037 private final CoreSession session; 038 039 public CoreSessionRegistrationInfo(CoreSession session) { 040 super("CoreSessionDebugInfo(" + Thread.currentThread().getName() + ", " + session.getSessionId() + ")"); 041 this.session = session; 042 } 043 044 public CoreSession getCoreSession() { 045 return session; 046 } 047 } 048 049 /** 050 * Instantiates a {@link CoreSession}. 051 * 052 * @param repositoryName the repository name 053 * @param principal the principal 054 * @return a {@link CoreSession} 055 */ 056 CoreSession createCoreSession(String repositoryName, NuxeoPrincipal principal); 057 058 /** 059 * Releases (closes) a {@link CoreSession} acquired by {@link #createCoreSession}. 060 * 061 * @param session the session to close 062 */ 063 void releaseCoreSession(CoreSession session); 064 065 /** 066 * Gets an existing open session for the given session id. 067 * <p> 068 * The returned {@link CoreSession} must not be closed, as it is owned by someone else. 069 * 070 * @param sessionId the session id 071 * @return the session, which must not be closed 072 */ 073 CoreSession getCoreSession(String sessionId); 074 075 /** 076 * Gets the number of open sessions. 077 */ 078 int getNumberOfOpenCoreSessions(); 079 080 /** 081 * Gets the debug info for the open sessions. 082 * 083 * @return a list of debug info 084 */ 085 List<CoreSessionRegistrationInfo> getCoreSessionRegistrationInfos(); 086 087}