javatips.net counter

Java Examples for com.google.inject.Singleton

The following java examples will help you to understand the usage of com.google.inject.Singleton. These source code samples are taken from different open source projects.

Example 1
Project: sitebricks-master  File: SitebricksConfig.java View source code
@Override
protected void configureSitebricks() {
    install(new ChannelModule("/channel") {

        @Override
        protected void configureChannels() {
            processAll().with(Chatter.class);
            bind(ChannelListener.class).to(Chatter.ChatterListener.class);
        }
    });
    // TODO(dhanji): find a way to run the suite again with this module installed.
    //        install(new GaeModule());
    bind(FlashCache.class).to(HttpSessionFlashCache.class).in(Singleton.class);
    // TODO We should run the test suite once with this turned off and with scan() on.
    //        scan(SitebricksConfig.class.getPackage());
    bindExplicitly();
    bindActions();
    bindCrudActions();
    // Bind a dummy interceptor to specifically test AOP interaction with decorated pages.
    bindInterceptor(Matchers.annotatedWith(Decorated.class), Matchers.any(), new MethodInterceptor() {

        @Override
        public Object invoke(MethodInvocation methodInvocation) throws Throwable {
            return methodInvocation.proceed();
        }
    });
    at("/no_annotations/service").serve(RestfulWebServiceNoAnnotations.class);
    at("/debug").show(DebugPage.class);
    bind(Start.class).annotatedWith(Test.class).to(Start.class);
    // Localize using the default translation set (i.e. from the @Message annotations)
    localize(I18n.MyMessages.class).usingDefault();
    localize(I18n.MyMessages.class).using(Locale.CANADA_FRENCH, ImmutableMap.of(I18n.HELLO, I18n.HELLO_IN_FRENCH));
    localize(HtmlValidating.ErrorMessages.class).usingDefault();
    localize(HtmlValidatingAsForm.ErrorMessages.class).usingDefault();
    install(new StatModule("/stats"));
    converter(new DateConverters.DateStringConverter(DEFAULT_DATE_TIME_FORMAT));
    install(new AwareModule() {

        @Override
        protected void configureLifecycle() {
            observe(StartAware.class).asEagerSingleton();
        }
    });
    // Validation
    install(new ValidationModule());
}
Example 2
Project: WaveInCloud-master  File: ServerRpcProvider.java View source code
public ServletModule getServletModule(final Injector injector) {
    return new ServletModule() {

        @Override
        protected void configureServlets() {
            // http://web.archiveorange.com/archive/v/d0LdlXf1kN0OXyPNyQZp
            for (Pair<String, ServletHolder> servlet : servletRegistry) {
                String url = servlet.getFirst();
                @SuppressWarnings({ "unchecked" }) Class<HttpServlet> clazz = servlet.getSecond().getHeldClass();
                @SuppressWarnings({ "unchecked" }) Map<String, String> params = servlet.getSecond().getInitParameters();
                serve(url).with(clazz, params);
                bind(clazz).in(Singleton.class);
            }
        }
    };
}
Example 3
Project: palava-ipc-xml-rpc-master  File: XmlRpcNettyModule.java View source code
@Override
public void configure(Binder binder) {
    binder.bind(HttpRequestDecoder.class).in(Scopes.NO_SCOPE);
    binder.bind(HttpResponseEncoder.class).in(Singleton.class);
    binder.bind(HttpHandler.class).in(Singleton.class);
    binder.bind(JaxbDecoder.class).in(Singleton.class);
    binder.bind(JaxbEncoder.class).in(Singleton.class);
    binder.bind(MethodCallDecoder.class).in(Singleton.class);
    binder.bind(MethodResponseEncoder.class).in(Singleton.class);
    binder.bind(XmlRpcHandler.class).in(Singleton.class);
    binder.bind(Key.get(Schema.class, XmlRpc.class)).toProvider(XmlRpcSchemaProvider.class).in(Singleton.class);
    binder.bind(Marshaller.class).annotatedWith(XmlRpc.class).toProvider(XmlRpcMarshallerProvider.class);
    binder.bind(Unmarshaller.class).annotatedWith(XmlRpc.class).toProvider(XmlRpcUnmarshallerProvider.class);
    binder.install(new AdapterModule());
}
Example 4
Project: usergrid-master  File: GraphModule.java View source code
/**
      * Configure via explicit declaration the migration path we can follow
      * @param v1
      * @param v2
      * @return
      */
@Singleton
@Inject
@Provides
public VersionedMigrationSet<EdgeMetadataSerialization> getVersions(final EdgeMetadataSerializationV1Impl v1, final EdgeMetadataSerializationV2Impl v2) {
    //migrate from v1 to v2
    MigrationRelationship<EdgeMetadataSerialization> v1Tov2 = new MigrationRelationship<>(v1, v2);
    //keep our curent tuple, v2, v2
    MigrationRelationship<EdgeMetadataSerialization> current = new MigrationRelationship<EdgeMetadataSerialization>(v2, v2);
    //now create our set of versions
    VersionedMigrationSet<EdgeMetadataSerialization> set = new VersionedMigrationSet<>(v1Tov2, current);
    return set;
}
Example 5
Project: sisu-guice-master  File: ElementsTest.java View source code
public void testBindInScopes() {
    checkModule(new AbstractModule() {

        @Override
        protected void configure() {
            bind(String.class);
            bind(List.class).to(ArrayList.class).in(Scopes.SINGLETON);
            bind(Map.class).to(HashMap.class).in(Singleton.class);
            bind(Set.class).to(TreeSet.class).asEagerSingleton();
        }
    }, new FailingElementVisitor() {

        @Override
        public <T> Void visit(Binding<T> command) {
            assertEquals(Key.get(String.class), command.getKey());
            command.acceptScopingVisitor(new FailingBindingScopingVisitor() {

                @Override
                public Void visitNoScoping() {
                    return null;
                }
            });
            return null;
        }
    }, new FailingElementVisitor() {

        @Override
        public <T> Void visit(Binding<T> command) {
            assertEquals(Key.get(List.class), command.getKey());
            command.acceptScopingVisitor(new FailingBindingScopingVisitor() {

                @Override
                public Void visitScope(Scope scope) {
                    assertEquals(Scopes.SINGLETON, scope);
                    return null;
                }
            });
            return null;
        }
    }, new FailingElementVisitor() {

        @Override
        public <T> Void visit(Binding<T> command) {
            assertEquals(Key.get(Map.class), command.getKey());
            command.acceptScopingVisitor(new FailingBindingScopingVisitor() {

                @Override
                public Void visitScopeAnnotation(Class<? extends Annotation> annotation) {
                    assertEquals(Singleton.class, annotation);
                    return null;
                }
            });
            return null;
        }
    }, new FailingElementVisitor() {

        @Override
        public <T> Void visit(Binding<T> command) {
            assertEquals(Key.get(Set.class), command.getKey());
            command.acceptScopingVisitor(new FailingBindingScopingVisitor() {

                @Override
                public Void visitEagerSingleton() {
                    return null;
                }
            });
            return null;
        }
    });
}
Example 6
Project: aokp-gerrit-master  File: Reindex.java View source code
@Provides
@Singleton
@MergeabilityChecksExecutor(Priority.BACKGROUND)
public WorkQueue.Executor createMergeabilityChecksExecutor(WorkQueue queues) {
    return queues.createQueue(1, "MergeabilityChecks");
}
Example 7
Project: torodb-master  File: BackendModule.java View source code
@Override
protected void configure() {
    bind(SqlInterfaceDelegate.class).in(Singleton.class);
    bind(SqlInterface.class).to(SqlInterfaceDelegate.class);
    expose(SqlInterface.class);
    bind(BackendTransactionJobFactory.class).to(BackendConnectionJobFactoryImpl.class).in(Singleton.class);
    expose(BackendTransactionJobFactory.class);
    bind(ReservedIdInfoFactoryImpl.class).in(Singleton.class);
    bind(ReservedIdInfoFactory.class).to(ReservedIdInfoFactoryImpl.class);
    bind(ReservedIdGeneratorImpl.class).in(Singleton.class);
    bind(ReservedIdGenerator.class).to(ReservedIdGeneratorImpl.class);
    expose(ReservedIdGenerator.class);
    bind(DslContextFactoryImpl.class).in(Singleton.class);
    bind(DslContextFactory.class).to(DslContextFactoryImpl.class);
    bind(SnapshotUpdaterImpl.class);
    bind(SnapshotUpdater.class).to(SnapshotUpdaterImpl.class);
    expose(SnapshotUpdater.class);
    install(new FactoryModuleBuilder().implement(BackendBundle.class, BackendBundleImpl.class).build(BackendBundleFactory.class));
    expose(BackendBundleFactory.class);
    bind(SqlHelper.class).in(Singleton.class);
    expose(SqlHelper.class);
    bind(BackendServiceImpl.class).in(Singleton.class);
    bind(KvMetainfoHandler.class);
}
Example 8
Project: mycila-master  File: InjectInBeanTest.java View source code
// You can even bind a method, and you can specify scopes
@Bind(scope = Singleton.class)
C create() {
    return new C();
}
Example 9
Project: airlift-master  File: LifeCycleModule.java View source code
@Provides
@Singleton
public LifeCycleManager getServerManager() throws Exception {
    LifeCycleManager lifeCycleManager = new LifeCycleManager(injectedInstances, lifeCycleMethodsMap);
    this.lifeCycleManager.set(lifeCycleManager);
    return lifeCycleManager;
}
Example 10
Project: incubator-wave-master  File: WaveServerModule.java View source code
@Override
protected void configure() {
    bind(TimeSource.class).to(DefaultTimeSource.class).in(Singleton.class);
    if (enableFederation) {
        bind(SignatureHandler.class).toProvider(SigningSignatureHandler.SigningSignatureHandlerProvider.class);
    } else {
        bind(SignatureHandler.class).toProvider(NonSigningSignatureHandler.NonSigningSignatureHandlerProvider.class);
    }
    try {
        bind(WaveSignatureVerifier.class).toConstructor(WaveSignatureVerifier.class.getConstructor(WaveCertPathValidator.class, CertPathStore.class));
        bind(VerifiedCertChainCache.class).to(DefaultCacheImpl.class).in(Singleton.class);
        bind(DefaultCacheImpl.class).toConstructor(DefaultCacheImpl.class.getConstructor(TimeSource.class));
    } catch (NoSuchMethodException e) {
        throw new IllegalStateException(e);
    }
    bind(WaveletNotificationDispatcher.class).in(Singleton.class);
    bind(WaveBus.class).to(WaveletNotificationDispatcher.class);
    bind(WaveletNotificationSubscriber.class).to(WaveletNotificationDispatcher.class);
    bind(TrustRootsProvider.class).to(DefaultTrustRootsProvider.class).in(Singleton.class);
    bind(CertificateManager.class).to(CertificateManagerImpl.class).in(Singleton.class);
    bind(DeltaAndSnapshotStore.class).to(DeltaStoreBasedSnapshotStore.class).in(Singleton.class);
    bind(WaveMap.class).in(Singleton.class);
    bind(WaveletProvider.class).to(WaveServerImpl.class).asEagerSingleton();
    bind(ReadableWaveletDataProvider.class).to(WaveServerImpl.class).in(Singleton.class);
    bind(HashedVersionFactory.class).toInstance(HASH_FACTORY);
}
Example 11
Project: eadventure-master  File: DesktopModule.java View source code
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {
    BasicModuleMap map = new BasicModuleMap();
    map.setBind(AssetHandler.class, DesktopAssetHandler.class);
    map.setBind(GUI.class, DesktopGUI.class);
    for (Entry<Class<?>, Class<?>> e : map.getBinds().entrySet()) {
        TypeLiteral typeLiteral = TypeLiteral.get(e.getKey());
        if (!binds.containsKey(typeLiteral)) {
            binds.put(typeLiteral, e.getValue());
        }
    }
    TypeLiteral<SpecialAssetRenderer<EAdVideo, ?>> t = new TypeLiteral<SpecialAssetRenderer<EAdVideo, ?>>() {
    };
    if (!binds.containsKey(t)) {
        binds.put(t, VLC2VideoRenderer.class);
    // bind(new TypeLiteral<SpecialAssetRenderer<EAdVideo, ?>>() {
    // }).to(JavaVideoRenderer.class);
    }
    for (Entry<TypeLiteral<?>, Class<?>> entry : binds.entrySet()) {
        TypeLiteral type = entry.getKey();
        Class c = entry.getValue();
        bind(type).to(c).in(Singleton.class);
    }
}
Example 12
Project: commons-old-master  File: ServerSetModule.java View source code
@Override
protected void configure() {
    requireBinding(ZooKeeperClient.class);
    requireBinding(ShutdownRegistry.class);
    requireBinding(LocalServiceRegistry.class);
    LifecycleModule.bindStartupAction(binder(), ServerSetJoiner.class);
    bind(new TypeLiteral<Supplier<EndpointStatus>>() {
    }).to(EndpointSupplier.class);
    bind(EndpointSupplier.class).in(Singleton.class);
    bind(Status.class).annotatedWith(Default.class).toInstance(initialStatus);
    Optional<String> primaryPortName;
    if (AUX_PORT_AS_PRIMARY.hasAppliedValue()) {
        primaryPortName = Optional.of(AUX_PORT_AS_PRIMARY.get());
    } else {
        primaryPortName = auxPortAsPrimary;
    }
    bind(new TypeLiteral<Optional<String>>() {
    }).annotatedWith(Default.class).toInstance(primaryPortName);
}
Example 13
Project: keywhiz-master  File: ServiceModule.java View source code
// AuditLog
@Provides
@Singleton
AuditLog simpleLogger() {
    return new SimpleLogger();
}
Example 14
Project: platform-api-master  File: DtoTemplate.java View source code
private void emitPreamble(StringBuilder builder) {
    builder.append("/*******************************************************************************\n");
    builder.append(" * Copyright (c) 2012-2014 Codenvy, S.A.\n");
    builder.append(" * All rights reserved. This program and the accompanying materials\n");
    builder.append(" * are made available under the terms of the Eclipse Public License v1.0\n");
    builder.append(" * which accompanies this distribution, and is available at\n");
    builder.append(" * http://www.eclipse.org/legal/epl-v10.html\n");
    builder.append(" *\n");
    builder.append(" * Contributors:\n");
    builder.append(" * Codenvy, S.A. - initial API and implementation\n");
    builder.append(" *******************************************************************************/\n\n\n");
    builder.append("// GENERATED SOURCE. DO NOT EDIT.\npackage ");
    builder.append(packageName);
    builder.append(";\n\n");
    if ("server".equals(implType)) {
        builder.append("import org.eclipse.che.dto.server.JsonSerializable;\n");
        builder.append("\n");
        builder.append("import com.google.gson.Gson;\n");
        builder.append("import com.google.gson.GsonBuilder;\n");
        builder.append("import com.google.gson.JsonArray;\n");
        builder.append("import com.google.gson.JsonElement;\n");
        builder.append("import com.google.gson.JsonNull;\n");
        builder.append("import com.google.gson.JsonObject;\n");
        builder.append("import com.google.gson.JsonParser;\n");
        builder.append("import com.google.gson.JsonPrimitive;\n");
        builder.append("\n");
        builder.append("import java.util.List;\n");
        builder.append("import java.util.Map;\n");
    }
    if ("client".equals(implType)) {
        builder.append("import org.eclipse.che.ide.dto.ClientDtoFactoryVisitor;\n");
        builder.append("import org.eclipse.che.ide.dto.DtoFactoryVisitor;\n");
        builder.append("import org.eclipse.che.ide.dto.JsonSerializable;\n");
        builder.append("import com.google.gwt.json.client.*;\n");
        builder.append("import com.google.inject.Singleton;\n");
    }
    builder.append("\n\[email protected]({\"unchecked\", \"cast\"})\n");
    if ("client".equals(implType)) {
        builder.append("@Singleton\n");
        builder.append("@ClientDtoFactoryVisitor\n");
    }
    // Note that we always use fully qualified path names when referencing Types
    // so we need not add any import statements for anything.
    builder.append("public class ");
    builder.append(className);
    if ("server".equals(implType)) {
        builder.append(" implements ").append(DtoFactoryVisitor.class.getCanonicalName());
    }
    if ("client".equals(implType)) {
        builder.append(" implements ").append("DtoFactoryVisitor");
    }
    builder.append(" {\n\n");
    if ("server".equals(implType)) {
        builder.append("  private static final Gson gson = new GsonBuilder().disableHtmlEscaping().serializeNulls().create();\n\n");
        builder.append("  @Override\n" + "  public void accept(org.eclipse.che.dto.server.DtoFactory dtoFactory) {\n");
        for (DtoImpl dto : getDtoInterfaces()) {
            String dtoInterface = dto.getDtoInterface().getCanonicalName();
            builder.append("    dtoFactory.registerProvider(").append(dtoInterface).append(".class").append(", ").append("new org.eclipse.che.dto.server.DtoProvider<").append(dtoInterface).append(">() {\n");
            builder.append("        public Class<? extends ").append(dtoInterface).append("> getImplClass() {\n").append("            return ").append(dto.getImplClassName()).append(".class;\n");
            builder.append("        }\n\n");
            builder.append("        public ").append(dtoInterface).append(" newInstance() {\n").append("            return ").append(dto.getImplClassName()).append(".make();\n");
            builder.append("        }\n\n");
            builder.append("        public ").append(dtoInterface).append(" fromJson(String json) {\n").append("            return ").append(dto.getImplClassName()).append(".fromJsonString(json);\n");
            builder.append("        }\n\n");
            builder.append("        public ").append(dtoInterface).append(" fromJson(com.google.gson.JsonElement json) {\n").append("            return ").append(dto.getImplClassName()).append(".fromJsonElement(json);\n");
            builder.append("        }\n\n");
            builder.append("        public ").append(dtoInterface).append(" clone(").append(dtoInterface).append(" origin) {\n").append("            return new ").append(dto.getImplClassName()).append("(origin);\n");
            builder.append("        }\n");
            builder.append("    });\n");
        }
        builder.append("  }\n\n");
    }
    if ("client".equals(implType)) {
        builder.append("  @Override\n").append("  public void accept(org.eclipse.che.ide.dto.DtoFactory dtoFactory) {\n");
        for (DtoImpl dto : getDtoInterfaces()) {
            String dtoInterface = dto.getDtoInterface().getCanonicalName();
            builder.append("    dtoFactory.registerProvider(").append(dtoInterface).append(".class").append(", ").append("new org.eclipse.che.ide.dto.DtoProvider<").append(dtoInterface).append(">() {\n");
            builder.append("        public Class<? extends ").append(dtoInterface).append("> getImplClass() {\n").append("            return ").append(dto.getImplClassName()).append(".class;\n");
            builder.append("        }\n\n");
            builder.append("        public ").append(dtoInterface).append(" newInstance() {\n").append("            return ").append(dto.getImplClassName()).append(".make();\n");
            builder.append("        }\n\n");
            builder.append("        public ").append(dtoInterface).append(" fromJson(String json) {\n").append("            return ").append(dto.getImplClassName()).append(".fromJsonString(json);\n");
            builder.append("        }\n");
            builder.append("    });\n");
        }
        builder.append("  }\n\n");
    }
}