@Service @Scoped(PerLookup.class) public class CrDecorator implements CreationDecorator<SecureAdminInternalUser> { @Param(optional=false, primary=true) private String username; @Param(optional=false) private String passwordAlias; @Inject private SecureAdminHelper helper; @Override public void decorate(AdminCommandContext context, SecureAdminInternalUser instance) throws TransactionFailure, PropertyVetoException { try { helper.validateInternalUsernameAndPasswordAlias( username, passwordAlias); } catch (Exception ex) { throw new TransactionFailure("create", ex); } instance.setUsername(username); instance.setPasswordAlias(passwordAlias); } } }
/** * Start a stopped virtual machine. * @author Jerome Dochez */ @Service(name="start-vm") @Scoped(PerLookup.class) public class StartVirtualMachine extends VirtualMachineMgt implements AdminCommand { @Inject VirtualMachineLifecycle vmLifecycle; @Override void doWork(VirtualMachine vm) throws VirtException { vmLifecycle.start(vm); } }
if (scoped == null) { throw new CommandException(strings.get("NoScope", name)); } else if (scoped.value() == Singleton.class) { if (opt.getParam().password()) continue; // passwords are handled later if (opt.getParam().obsolete() && getOption(opt.getName()) != null) logger.info( strings.get("ObsoleteOption", opt.getName())); if (opt.getParam().optional()) continue; if (opt.getParam().primary())
/** * {@link Scope} local to each invocation. * * <p> * Components in this scope will create new instances every time someone asks for it. * * @author Kohsuke Kawaguchi */ @Scoped(Singleton.class) public class PerLookup extends Scope { @Override public ScopeInstance current() { return new ScopeInstance(new HashMap()); } }
/** * Creates a {@link Inhabitant} by wrapping {@link Creator} to handle scoping right. */ public static <T> Inhabitant<T> wrapByScope(Class<T> c, Creator<T> creator, Habitat habitat) { Scoped scoped = c.getAnnotation(Scoped.class); if (scoped==null) { return new SingletonInhabitant<T>(creator); // treated as singleton } Class<? extends Scope> scopeClass = scoped.value(); return wrapByScope(creator, habitat, scopeClass); }
@Service @Scoped(PerLookup.class) class DeleteDecorator implements DeletionDecorator<LbConfigs, LbConfig> { @Inject private Domain domain; @Override public void decorate(AdminCommandContext context, LbConfigs parent, LbConfig child) throws PropertyVetoException, TransactionFailure { Logger logger = LogDomains.getLogger(LbConfig.class, LogDomains.ADMIN_LOGGER); LocalStringManagerImpl localStrings = new LocalStringManagerImpl(LbConfig.class); String lbConfigName = child.getName(); LbConfig lbConfig = domain.getLbConfigs().getLbConfig(lbConfigName); //Ensure there are no refs if ( (lbConfig.getClusterRefOrServerRef().size() != 0 ) ) { String msg = localStrings.getLocalString("LbConfigNotEmpty", lbConfigName); throw new TransactionFailure(msg); } logger.info(localStrings.getLocalString("http_lb_admin.LbConfigDeleted", lbConfigName)); } } }
/** * Singleton scope. * * @author Kohsuke Kawaguchi */ @Scoped(Singleton.class) public class Singleton extends Scope { /** * @deprecated * Singleton instances are not stored in a single map. */ @Override public ScopeInstance current() { throw new UnsupportedOperationException(); } }
/** * Creates a {@link Inhabitant} by wrapping {@link Creator} to handle scoping right. */ public static <T> Inhabitant<T> wrapByScope(Class<T> c, Creator<T> creator, Habitat habitat) { Scoped scoped = c.getAnnotation(Scoped.class); if (scoped==null) { return new SingletonInhabitant<T>(creator); // treated as singleton } Class<? extends Scope> scopeClass = scoped.value(); return wrapByScope(creator, habitat, scopeClass); }
@Service @Scoped(PerLookup.class) public static class CrDecorator implements CreationDecorator<SecureAdminPrincipal> { @Inject(/*name=CREATION_DECORATOR_NAME*/) private SecureAdminHelper helper; @Param(optional=false, name="value", primary=true) private String value; @Param(optional=true, name="alias", defaultValue="false") private boolean isAlias = true;
/** * List existing virtual machines * @author Jerome Dochez */ @Service(name="list-vms") @Scoped(PerLookup.class) public class ListVirtualMachines implements AdminCommand { @Inject IAAS gm; @Override public void execute(AdminCommandContext context) { //To change body of implemented methods use File | Settings | File Templates. try { for (ServerPool group : gm) { context.getActionReport().setMessage("For Group : " + group.getName()); for (VirtualMachine vm : group.getVMs()) { context.getActionReport().getTopMessagePart().addChild().setMessage( "Virtual Machine: " + vm.getName() + " is " + vm.getInfo().getState()); } } } catch(VirtException e) { context.getActionReport().failure(Logger.getAnonymousLogger(), "Exception while listing machines ", e); } } }
@Service @Scoped(Singleton.class) public class DummyCallFlowAgentImpl implements CallFlowAgent { public boolean isEnabled() {return false;} public void entityManagerMethodStart(EntityManagerMethod val) {} public void entityManagerMethodEnd() {} public void entityManagerQueryStart(EntityManagerQueryMethod val) {} public void entityManagerQueryEnd() {} }
/** * * @author PRASHANTH ABBAGANI * * Factory class which returns the appropriate ResourceManager */ @Service(name="resource-factory") @Scoped(PerLookup.class) @I18n("add.resources") public class ResourceFactory { @Inject private Habitat habitat; public ResourceManager getResourceManager(Resource resource) { String resourceType = resource.getType(); ResourceManager resourceManager = null; for (ResourceManager rm : habitat.getAllByContract(ResourceManager.class)) { if ((rm.getResourceType()).equals(resourceType)) { resourceManager = rm; break; } } return resourceManager; } }
/** * * @author Jerome Dochez */ @Service(name="list-applications") @I18n("list.applications") @Scoped(PerLookup.class) @CommandLock(CommandLock.LockType.NONE) @ExecuteOn(value={RuntimeType.DAS}) @TargetType(value={CommandTarget.DOMAIN, CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER}) public class ListApplicationsCommand extends ListComponentsCommand { public void execute(AdminCommandContext context) { super.execute(context); } }
/** * Scans for annotations relevant to persistence units that indicate an app * client depends on at least one persistence unit. * * @author tjquinn */ @Service(name="car") @Scoped(Singleton.class) public class AppClientPersistenceDependencyAnnotationScanner extends AbstractAnnotationScanner { protected void init(java.util.Set<String> annotationsSet) { annotationsSet.add("Ljavax/persistence/PersistenceUnit"); annotationsSet.add("Ljavax/persistence/PersistenceUnits"); } }