本文整理汇总了Java中com.google.inject.internal.UniqueAnnotations类的典型用法代码示例。如果您正苦于以下问题:Java UniqueAnnotations类的具体用法?Java UniqueAnnotations怎么用?Java UniqueAnnotations使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UniqueAnnotations类属于com.google.inject.internal包,在下文中一共展示了UniqueAnnotations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
public static void main(String[] args) {
LifeManager manager = new LifeManager();
manager.add(Guice.createInjector(new PrivateModule() {
@Override
protected void configure() {
bind(Service.class).annotatedWith(Names.named("1"))
.to(ServiceImpl.class)
.in(Scopes.SINGLETON);
expose(Service.class).annotatedWith(Names.named("1"));
bind(ImplWorker.class).toInstance(new ImplWorker() {
@Override
public void work() {
System.out.println("work 1 done");
}
});
}
}, new PrivateModule() {
@Override
protected void configure() {
bind(Service.class).annotatedWith(Names.named("2"))
.to(ServiceImpl.class)
.in(Scopes.SINGLETON);
expose(Service.class).annotatedWith(Names.named("2"));
bind(ImplWorker.class).toInstance(new ImplWorker() {
@Override
public void work() {
System.out.println("work 2 done");
}
});
}
}, new AbstractModule() {
@Override
protected void configure() {
final Annotation id = UniqueAnnotations.create();
bind(Listener.class).annotatedWith(id).to(Client.class).asEagerSingleton();
}
}));
manager.start();
}
示例2: configure
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
@Override
protected void configure() {
bind(DestinationFactory.class).in(Scopes.SINGLETON);
bind(ReplicationQueue.class).in(Scopes.SINGLETON);
DynamicSet.bind(binder(), GitReferenceUpdatedListener.class).to(ReplicationQueue.class);
DynamicSet.bind(binder(), NewProjectCreatedListener.class).to(ReplicationQueue.class);
DynamicSet.bind(binder(), ProjectDeletedListener.class).to(ReplicationQueue.class);
DynamicSet.bind(binder(), HeadUpdatedListener.class).to(ReplicationQueue.class);
bind(OnStartStop.class).in(Scopes.SINGLETON);
bind(LifecycleListener.class).annotatedWith(UniqueAnnotations.create()).to(OnStartStop.class);
bind(LifecycleListener.class)
.annotatedWith(UniqueAnnotations.create())
.to(ReplicationLogFile.class);
bind(CredentialsFactory.class)
.to(AutoReloadSecureCredentialsFactoryDecorator.class)
.in(Scopes.SINGLETON);
bind(CapabilityDefinition.class)
.annotatedWith(Exports.named(START_REPLICATION))
.to(StartReplicationCapability.class);
install(new FactoryModuleBuilder().build(PushAll.Factory.class));
install(new FactoryModuleBuilder().build(RemoteSiteUser.Factory.class));
bind(ReplicationConfig.class).to(AutoReloadConfigDecorator.class);
bind(ReplicationStateListener.class).to(ReplicationStateLogger.class);
EventTypes.register(RefReplicatedEvent.TYPE, RefReplicatedEvent.class);
EventTypes.register(RefReplicationDoneEvent.TYPE, RefReplicationDoneEvent.class);
EventTypes.register(ReplicationScheduledEvent.TYPE, ReplicationScheduledEvent.class);
bind(SshSessionFactory.class).toProvider(ReplicationSshSessionFactoryProvider.class);
}
示例3: configure
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
@Override
protected final void configure()
{
internalConfigure();
configureServlets();
for ( FilterDefinition filterDefinition : filterDefinitions )
{
bind(FilterDefinition.class).annotatedWith(UniqueAnnotations.create()).toInstance(filterDefinition);
}
for ( ServletDefinition servletDefinition : servletDefinitions )
{
bind(ServletDefinition.class).annotatedWith(UniqueAnnotations.create()).toInstance(servletDefinition);
}
}
示例4: visit
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
@Override
public <T> Void visit(Binding<T> binding) {
final Key<T> key = binding.getKey();
if (!keysToIntercept.contains(key)) {
return super.visit(binding);
}
binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
@Override
public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
binder.addError("Cannot intercept bare binding of %s. " +
"You may only intercept bindings that bind a class to something.", key);
return null;
}
});
Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));
ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);
// we scope the user's provider, not the interceptor. This is dangerous,
// but convenient. It means that although the user's provider will live
// in its proper scope, the intereptor gets invoked without a scope
applyScoping(binding, scopedBindingBuilder);
keysIntercepted.add(key);
return null;
}
示例5: visit
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
@Override
public <T> Void visit(Binding<T> binding) {
final Key<T> key = binding.getKey();
if (!keysToIntercept.contains(key)) {
return super.visit(binding);
}
binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
@Override
public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
binder.addError("Cannot intercept bare binding of %s. " +
"You may only intercept bindings that bind a class to something.", key);
return null;
}
});
Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));
ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);
// we scope the user's provider, not the interceptor. This is dangerous,
// but convenient. It means that although the user's provider will live
// in its proper scope, the interceptor gets invoked without a scope
applyScoping(binding, scopedBindingBuilder);
keysIntercepted.add(key);
return null;
}
示例6: bindServlet
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
protected <T extends HttpServlet> ServletBindingBuilder bindServlet(Class<T> servlet)
{
Annotation annotation = UniqueAnnotations.create();
Key<T> servletKey = Key.get(servlet, UniqueAnnotations.create());
binder().bind(servletKey).to(servlet).in(Scopes.SINGLETON);
return new ServletBindingBuilder(binder(), servletKey);
}
示例7: addResources
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ApplicationBindingBuilder addResources(Class<?>... annotatedClass)
{
for (Class<?> clazz : annotatedClass) {
Key<Object> key = Key.get((Class<Object>) clazz, UniqueAnnotations.create());
binder.bind(key).to(clazz);
initializer.addResource(key, clazz);
}
return this;
}
示例8: addProvider
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ApplicationBindingBuilder addProvider(Class<?> annotatedClass)
{
Key<Object> key = Key.get((Class<Object>) annotatedClass, UniqueAnnotations.create());
binder.bind(key).to(annotatedClass);
initializer.addProvider(key);
return this;
}
示例9: addProviderInstance
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ApplicationBindingBuilder addProviderInstance(Object object)
{
Key<Object> key = Key.get((Class<Object>) object.getClass(), UniqueAnnotations.create());
binder.bind(key).toInstance(object);
initializer.addProvider(key);
return this;
}
示例10: rpc
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
protected void rpc(String name, Class<? extends RemoteJsonService> clazz) {
final Key<GerritJsonServlet> srv = Key.get(GerritJsonServlet.class, UniqueAnnotations.create());
final GerritJsonServletProvider provider = new GerritJsonServletProvider(clazz);
bind(clazz);
serve(prefix + name).with(srv);
bind(srv).toProvider(provider).in(Scopes.SINGLETON);
}
示例11: key
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
private Key<HttpServlet> key(HttpServlet servlet) {
final Key<HttpServlet> srv = Key.get(HttpServlet.class, UniqueAnnotations.create());
bind(srv)
.toProvider(
new Provider<HttpServlet>() {
@Override
public HttpServlet get() {
return servlet;
}
})
.in(SINGLETON);
return srv;
}
示例12: module
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
public static ServletModule module() {
return new ServletModule() {
@Override
protected void configureServlets() {
DynamicSet.setOf(binder(), AllRequestFilter.class);
filter("/*").through(FilterProxy.class);
bind(StopPluginListener.class)
.annotatedWith(UniqueAnnotations.create())
.to(FilterProxy.class);
}
};
}
示例13: configureServlets
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
@Override
protected void configureServlets() {
bind(HttpPluginServlet.class);
serveRegex("^/(?:a/)?plugins/(.*)?$").with(HttpPluginServlet.class);
bind(LfsPluginServlet.class);
serveRegex(LfsDefinitions.LFS_URL_REGEX).with(LfsPluginServlet.class);
bind(StartPluginListener.class)
.annotatedWith(UniqueAnnotations.create())
.to(HttpPluginServlet.class);
bind(ReloadPluginListener.class)
.annotatedWith(UniqueAnnotations.create())
.to(HttpPluginServlet.class);
bind(StartPluginListener.class)
.annotatedWith(UniqueAnnotations.create())
.to(LfsPluginServlet.class);
bind(ReloadPluginListener.class)
.annotatedWith(UniqueAnnotations.create())
.to(LfsPluginServlet.class);
bind(ModuleGenerator.class).to(HttpAutoRegisterModuleGenerator.class);
install(
new CacheModule() {
@Override
protected void configure() {
cache(PLUGIN_RESOURCES, ResourceKey.class, Resource.class)
.maximumWeight(2 << 20)
.weigher(ResourceWeigher.class);
}
});
DynamicMap.mapOf(binder(), DynamicOptions.DynamicBean.class);
}
示例14: calculateBindAnnotation
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
public static Annotation calculateBindAnnotation(Class<Object> impl) {
Annotation n = impl.getAnnotation(Export.class);
if (n == null) {
n = impl.getAnnotation(javax.inject.Named.class);
}
if (n == null) {
n = impl.getAnnotation(com.google.inject.name.Named.class);
}
if (n == null) {
n = UniqueAnnotations.create();
}
return n;
}
示例15: with
import com.google.inject.internal.UniqueAnnotations; //导入依赖的package包/类
private void with(
Key<? extends HttpServlet> servletKey,
Map<String, String> initParams,
HttpServlet servletInstance) {
for (UriPatternMatcher pattern : uriPatterns) {
binder
.bind(Key.get(ServletDefinition.class, UniqueAnnotations.create()))
.toProvider(new ServletDefinition(servletKey, pattern, initParams, servletInstance));
}
}