/*
* Copyright (C) 2011 Eiichiro Uchiumi. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eiichiro.gig.acidhouse;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import org.eiichiro.acidhouse.DatastoreSession;
import org.eiichiro.acidhouse.appengine.AppEngineStrongDatastoreSession;
import org.eiichiro.jazzmaster.Application;
import org.eiichiro.jazzmaster.management.Lifecycle;
import org.eiichiro.jazzmaster.management.Scope;
import org.eiichiro.jazzmaster.service.Service;
/**
* {@code AcidHouseAppEngineStrongDatastoreSession} is a Jazzmaster service
* to composite {@code AppEngineDatastoreSession} with your Jazzmaster component.
*
* @author <a href="mailto:eiichiro@eiichiro.org">Eiichiro Uchiumi</a>
*/
@Strong
public class AcidHouseAppEngineStrongDatastoreSession extends Service {
/**
* Returns {@code AppEngineStrongDatastoreSession} as Jazzmaster service
* implementation.
*/
@Override
public Class<?> getImplementation() {
return AppEngineStrongDatastoreSession.class;
}
/**
* Returns {@code Scope.REQUEST} if application is running on Web
* environment. Otherwise, returns {@code Scope.THREAD}.
*/
@Override
public Scope getScope() {
if (Application.isWeb()) {
return Scope.REQUEST;
} else {
return Scope.THREAD;
}
}
/**
* Returns {@code DatastoreSession#close()} method when this component is
* stopped.
*/
@Override
public Set<Method> getCallbacks(Lifecycle lifecycle) {
if (lifecycle == Lifecycle.STOPPED) {
Set<Method> set = new HashSet<Method>(1);
try {
Method method = DatastoreSession.class.getDeclaredMethod("close");
set.add(method);
} catch (Exception e) {}
return set;
} else {
return new HashSet<Method>(0);
}
}
}
|