Re: Desktop scoping and lifecycles
maybe you can try to use Onami Lifecycle Dispose support [1] or Lifecycle Management in Governator [2] hth, jordi [1] http://onami.apache.org/lifecycle/org.apache.onami.lifecycle.standard/dispose.html [2] https://github.com/Netflix/governator/wiki/Lifecycle-Management On Wed, Sep 4, 2013 at 7:06 PM, jon.mi...@gmail.com wrote: Thanks. Yeah that makes sense, I don't mind adding guice functionality or utilities if it simplifies the actual end code I write. What I want to avoid is writing some code then having to write more custom code just to get it bound properly and reusable. Seems that is what you have achieved with your child injectors + some generic management of them. Think I have some good ideas to play with now, thanks. On Tuesday, September 3, 2013 8:18:04 PM UTC+1, Nate Bauernfeind wrote: In this kind of situation I would try to put my non-reusable code behind [well-thought] interfaces as much as possible. Think about all the [known] use-cases and really try and separate the common logic from the custom logic. If you can hide the state behind a logical interface that has always been a huge win in my experiences. Also keep in mind the scope of the re-usability .. if you expect others to use it in non-guice scenarios, try hard to separate the needed Guice dependency into a separate maven/project module (basically a Guice convenience package). If the re-use is from within a single application, then assisted inject factories are the easiest way to go (easier than child injectors). If you choose to create a separate GuiceModule that brings all of the components together then be explicit about what things should be externally available (i.e. any implementation of your interfaces should be defined in a different GuiceModule (parent or sibling of your re-usable component)). Consider using interfaces for as many of the internal classes as makes sense ... because if someone doesn't like the default implementation then they can still easily create an override. I have previously used child injectors to create large object graphs that were configured by a couple of minor fields. I was able to reduce all sorts of awkward overhead by doing this. For example, I created a multi-bound list of tags that could be injected at any point in the graph to attach the tags to any metrics. There was a system that was in charge of constructing a new child injector, starting up the Managed classes and for shutting them down when they were no longer needed. It may have been what you're calling boiler plate, but I was extremely satisfied with the end result. I'm actually currently planning on going back to introduce a handful of interfaces (which I didn't originally think of doing) with the goal of making that part of that application easily plugin-able (which I'm anticipating will make it a lot friendlier for open sourcing). Nate On Tue, Aug 27, 2013 at 4:07 AM, jon@gmail.com wrote: Hi, Guice has had a big impact with the things I code, particular in developing and bringing together a modular system + then the testing that goes with it. However, I am struggling to find a nice way to do reusable components and in part is due to my inexperience with all of this. Examples of reusable components may be tabs in a browser or say in an IDE having drop in components like an n number of editors. So with the editors you have many classes that work together to make it happen and you need to it reusable / many concurrent uses some unique state. And when you close the editor, you may need to invoke the release of services / files they handle. I see three ways: 1. Factory / bioler plate code. 2. Child injectors, still requires a factory + bioler plate for the lifecycle. 3. A custom scope but have to manage the scope + entry/exit I dislike the first option, too much boiler plate. The second seems to work well and is probably the avenue I'm going down at the moment. The 3rd is what I am most confused about, everywhere I read says custom scopes are bad yet the Session and Request scope of servlets seem very handy and given I essentially need to manage state it seems like it is the answer. Any help would be great thanks. Thanks, Jon -- You received this message because you are subscribed to the Google Groups google-guice group. To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@**googlegroups.com. To post to this group, send email to google...@googlegroups.com. Visit this group at http://groups.google.com/**group/google-guicehttp://groups.google.com/group/google-guice . For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out . -- You received this message because you are subscribed to the Google Groups google-guice group. To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscr
Re: Factories
you can achieve that with a Multibindings [1] and MapBinder [2] In your module: public void configure() { MapBinderString, Service mapbinder = MapBinder.newMapBinder(binder(), String.class, Service.class); mapbinder.addBinding(SitemapListService.class.getName()).to(SitemapListService.class) // if you do it this way SitemapListService wil be also injected mapbinder.addBinding(SitemapService.class.getName()).to(SitemapService. class) // and so on } Now in your client code you can inject the map of services: @Inject Foo(MapString, Service services) { this.services = services; } hth, jordi [1] https://code.google.com/p/google-guice/wiki/Multibindings [2] http://google-guice.googlecode.com/svn/trunk/latest-javadoc/com/google/inject/multibindings/MapBinder.html On Thu, Aug 29, 2013 at 9:27 AM, jpcoo...@gmail.com wrote: Hi, I've been reading quite a lot of documentation around named bindings, factorymodulebuilder, mapped bindings and it is still not clear if I can achieve something along the following lines. For example I want a Factory to be able to look up different services at runtime based a key. In spring you can do something like this public class ServiceFactory { private MapString, Service services = new HashMapString, Service(); @Autowired private MapString, Service mappedServices; public void init() { services.put(SitemapListService.class.getName(), new SitemapListService()); services.put(SitemapService.class.getName(), new SitemapService()); services.put(SitemapExcelService.class.getName(), new SitemapExcelService()); services.put(CategoryService.class.getName(), new CategoryService()); services.put(AdminDirectoryListService.class.getName(), new AdminDirectoryListService()); services.put(CompositeConceptsService.class.getName(), new CompositeConceptsService()); } public Service getService(String key) { Service service = services.get(key); if (service == null) { throw new IllegalArgumentException(Unknown service type: + key); } return service; } } Then for example the service name could be configured in a configuration file or calculated at runtime? How can I achieve something similar with Guice? Thanks Jon -- You received this message because you are subscribed to the Google Groups google-guice group. To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscr...@googlegroups.com. To post to this group, send email to google-guice@googlegroups.com. Visit this group at http://groups.google.com/group/google-guice. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups google-guice group. To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscr...@googlegroups.com. To post to this group, send email to google-guice@googlegroups.com. Visit this group at http://groups.google.com/group/google-guice. For more options, visit https://groups.google.com/groups/opt_out.
Re: Managing non-obvious Scopes in complex Systems
On Sun, Jan 13, 2013 at 7:10 PM, Roger Kapsi rka...@gmail.com wrote: The difficulty is that I can't simply slap a @RequestScoped annotation onto them. Why can't you just annotate the type (eg: Account)? If the instance is not constructed by Guice, it will give enough information about the intended use. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Testing AOP and method names
On Wed, Dec 26, 2012 at 9:15 PM, Dirk Nimerem nene1...@sinnlos-mail.dewrote: Hi, Let's say i have a class which represents an user, called User and an interface implemented by this class called IUser. The IUser interface declares one method called sendMail(String text) for the user. Also i created an interceptor/ aspect via the Guice bindInterceptor method for my IUser. The aspect simply logs every call for the sendMail() method, that works fine. 1.) But how do i test, that my aspect works properly? I don't have an idea how to write an unit test for that. My idea was to create an IUser mock and trigger the public sendMail() method from outside. But how do I create an aspect on top of a mock? First, I think you should unit test the interceptor itself, making sure that the log event is called. It's a little tricky, but you can achieve that with Mockito and log4j. If you really want to test the interceptor is binded correctly, you should write some kinda functional / integration test case. Here, you'll start your the Injector and check that the log is written or something alike. 2.) In my aspect/ interceptor i simply check the methodname like this: if methodname == 'sendMail'. But if i rename/ refactor the sendMail Method my aspect won't work anymore. Is there a better way to to that? You should use custom annotation for that and apply it only on the methods you want logging. Then configure your interceptor like: bindInterceptor( any(), // classes annotatedWith(YourAnnon.class), // methods new YourLoggingInterceptor()); I think the examples about AOP in the wiki [1] are pretty clear, but let me know if I can help you further! Cheers! jordi [1] http://code.google.com/p/google-guice/wiki/AOP Thanks, Dirk -- You received this message because you are subscribed to the Google Groups google-guice group. To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/6flNLUy1tfwJ. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Current connection injection for a FTP client
I think that you're looking for Assisted Inject: http://code.google.com/p/google-guice/wiki/AssistedInject On Thu, Jul 5, 2012 at 9:14 PM, cheez u.int.3...@gmail.com wrote: I have a FTP client which has multiple servers configured by the user at runtime: class FTPConnection { FTPConnection(ServerInfo server, UserInfo user)... } I also have a client class which does something with the connection: class DoSomethingWithFTP { DoSomethingWithFTP(FTPConnection conn)... } For example, one type of DoSomethingWithFTP might be a DownloadAllTheThings process. What I'd like to do is have a notion of a current connection which is analogous to the current user. Nevermind that I probably wouldn't write code like this, all I want to do is figure out how I would inject the current FTP connection! So as you can see, a FTP connection requires some server info and user info. This is where I get stuck. The current connection is tied to these two values and they need to be injected into the FTPConnection. If it was a web app, I might scope these values to the session but what if I wanted to process all of them at once, in multiple threads? The pseudo-code I'd like to write is this: foreach( pairUserInfo,ServerInfo config : whatever() ) { makeNewThreadAndProcessThisSite(config); } This is a very simplified view of the whole thing. I probably will not write code like this but I think it's an approximate proxy for the problem I am really trying to solve. Would you kindly help me tease out a solution? Thanks! -- You received this message because you are subscribed to the Google Groups google-guice group. To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/5lXTdY069zEJ. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Can DI be used for Instantiating Value Objects
Bubba, I think that Christian responded to your questions in a very bookmarkable way ;) On Sun, May 13, 2012 at 4:51 PM, Christian Edward Gruber cgru...@google.com wrote: So here's a hello-worldish example, entirely off the top of my head: Foo - consumable Bar - consumable (product of a transformation) FooProcessor - collaborator Logger - collaborator LookupService - collaborator @Named(lookup.url) String processor - configuration And the classes would look sort of like this (assuming you used AssistedInject to create your Foo objects. interface FooProcessor { Bar transformFoo(Foo foo); } interface Foo { Integer getBaz(); } interface Bar { Integer getTransformedBaz(); } /** Factory interface used by AssistedInject to auto-wire a factory */ interface FooFactory { Foo create(Integer baz); } class FooImpl { private final Integer baz; private final Logger logger; @Inject public FooImpl( @AssistedInject Integer baz, Logger logger) { this.baz = baz; // Injected through the factory create method. this.logger = logger; // Injected from Guice } } class FooProcessorImpl { // fields @Inject FooProcessorImpl(Logger logger, LookupService lookupService) { // field assignments } public Bar transformFoo(Foo foo) { Precondition.notNull(foo, foo); return new BarImpl(lookupService.lookup(foo.getBaz()) * SOME_CONSTANT); } } class LookupService { // fields @Inject public LookupService(@Named(lookup.url) String lookupUrl) { // field assignments } public Integer lookup(Integer int) { // lookup integer from remote service via the lookup url. } } So, Foo and Bar are passed around on the call stack, and consumed and created by the collaborators (one collaborator of which is an auto-generated FooFactory implementation created by the AssistedInject extension system). The collaborators delegate different responsibilities to each other, and the configuration contextualizes collaborators. LookupService injects configuration - a named value, presumably wired into Guice via Names.bindProperties(Properties p) or jCommander+gCommander or something similar. This is just how I think of things - a useful breakdown. But, generally, I find that when I segregate responsibilities like this, I have far more composable code, and it becomes quickly clear whether something shoudl be injected or managed by factories or other services. cheers, Christian. On May 12, 2012, at 12:29 PM, Bubba 42 wrote: Many thanks guys for the input. Is there an example (Hello World level of complexity) which illustrates the collaborators, configuration, and consumables stereotypes? I'd be happy to put one together if it'd benefit folks -- but would need help. Thanks. On May 11, 5:23 pm, Christian Edward Gruber cgru...@google.com wrote: Please don't inject value classes, generally speaking. I tend to think of dependencies in three kinds - collaborators, configuration, and consumables. Consumables are value classes that are consumed by and transformed by your collaborators, in the context of your configuration. Generally consumables are passed on the function call stack through parameters, whereas collaborators should be injected (for testability, decoupling, and all the various other reasons). Configuration may be passed through either, but pick a strategy and go with it. That's my basic position. AssistedInject is wonderful, but slightly missed named - think of it as Assisted Auto-Wiring of Factories. It's a good thing. The above isn't to say you can't do it, and several frameworks built on top of guice or other DI systems do just that, but it's tricky and very likely to get subtle implicit behaviour that's hard for other developers to reason about. Common cases are for things like User objects to be injected into session-scoped objects. In that case, a user is not consumable data, but configuration - the context in which other things are mutated and created by the collaborators. But it's important that you get your mind clear about what's what in your system so you can apply a consistent strategy to it all. Christian On May 11, 2012, at 7:05 AM, jordi wrote: In case you really need to inject value classes, Guice does that for you for free. If you @Inject a Person (non-scoped), every time will give a new Person. But I can't figure out why a simple value class should be managed by Guice. In this case I'm sure that's easier and clearer to just use a regular, old-fashioned new. If what you're looking for is to inject a Service in conjunction with some value class, take a look at Assisted Inject [1] hth, jordi [1]http://code.google.com/p/google-guice/wiki/AssistedInject On Thu, May 10, 2012 at 10:45 PM, Bubba 42 bubba424...@gmail.com wrote: Hi, I've been unable to find a suitable answer to this question
Re: Can DI be used for Instantiating Value Objects
In case you really need to inject value classes, Guice does that for you for free. If you @Inject a Person (non-scoped), every time will give a new Person. But I can't figure out why a simple value class should be managed by Guice. In this case I'm sure that's easier and clearer to just use a regular, old-fashioned new. If what you're looking for is to inject a Service in conjunction with some value class, take a look at Assisted Inject [1] hth, jordi [1] http://code.google.com/p/google-guice/wiki/AssistedInject On Thu, May 10, 2012 at 10:45 PM, Bubba 42 bubba424...@gmail.com wrote: Hi, I've been unable to find a suitable answer to this question. If I understand this correctly: Dependency Injection can be used to instantiate service objects -- object that essentially abstract away some computational service ... for example (an instance of this class would essentially be stateless, save for resources that it might be plugged into such as SimpleMath.properties, and I would expect that there would be small number of instances of this class per application instance say under 5): class SimpleMath { public int addTwoNumbers (int n1, int n2) { return n1 + n2; } public int multiplyTwoNumbers (int n1, int n2) { return n1 * n2; } } Now can DI be used to instantiate value objects (for the lack of a better word). By a value object I mean an object that has state and the methods are impacted by that state, for example (as opposed to the previous class I would expect there to be hundreds or thousands of instances of this class): class Person { int age; int weight; String fname; String lname; // and so on public String hail() { return Hello to you to, I am + fname + + lname; } public String howOldAreYou() { return I don't really like talking about my age but I'm + age + years young; } // and so on } Thanks. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Could not expose() suggestion
Recently I've been stuck with this error: Could not expose() com.trovit.stopwords.persist.StopwordsMapper annotated with @com.google.inject.name.Named(value=foo_db), it must be explicitly bound. at com.trovit.stopwords.MultiMapperModule$1.configure(MultiMapperModule.java:55) Many errors in Guice have some really useful messages like Did you forget to Later I've realized that I forgot to bind my type in the PrivateModule, when I found testExposeButNoBind in PrivateModuleTest. I know it says it must be explicity bound, but can you add something like Did you forget to explicitly bind it?. I think it would be pretty much clear. cheers, jordi -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: binding date using properties
use a regular guice Matcher [1], I guess this would do the trick: import static com.google.inject.matcher.Matchers.annotatedWith; // ... protected void configure() { convertToTypes(annotatedWith(Names.named(YOUR_KEY)), typeConverter); } jordi [1] http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/matcher/Matchers.html On Tue, Jan 31, 2012 at 5:20 PM, Eyal Golan egola...@gmail.com wrote: Thanks for the inputs. The code example is what I needed. However, using it will convert all Date classes that get injected. Is there a way to create a converter only for parameters annotated with Named ? Eyal Golan egola...@gmail.com Visit: http://jvdrums.sourceforge.net/ LinkedIn: http://www.linkedin.com/in/egolan74 Skype: egolan74 P Save a tree. Please don't print this e-mail unless it's really necessary On Tue, Jan 31, 2012 at 5:55 PM, Tim Peierls t...@peierls.net wrote: I recommend using Rocoto, too, but here's an example that shows how to do it yourself, expressed as a JUnit test: http://pastebin.com/mWx9xG4M --tim On Tue, Jan 31, 2012 at 10:10 AM, Stuart McCulloch mccu...@gmail.comwrote: On 31 Jan 2012, at 14:42, egolan wrote: Hi, I am using Names.bindProperties(binder(), properties); where my properties are taken from a pre-initialized configuration. One of the properties represent java.util.Date. We have a simple date format class that sets the value: SimpleDateFormat dateFormat = new SimpleDateFormat(MM-dd- HH:mm:ss); when I just use the Names binding, I get the Guice creation exception that the named field was not bound. Names.bindProperties(...) creates constant bindings for the properties map - constant bindings are converted from Strings to actual instances by TypeConverters: http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/spi/TypeConverter.html Guice provides built-in TypeConverters for primitive types, enums, and class literals - but not for Date, hence the creation exception. However, you can add your own: http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/Binder.html#convertToTypes(com.google.inject.matcher.Matcher%3C?%20super%20com.google.inject.TypeLiteral%3C?%3E%3E,%20com.google.inject.spi.TypeConverter) See also http://99soft.github.com/rocoto/ which provides a range of useful TypeConverters, including one for Date: http://99soft.github.com/rocoto/converters.html This is my injected constructor: @Inject public CoreFetchOperationsImpl(@Named(MpsQueryFilter) String genericQuery, @Named(MpsIterationBulkSize)int bulkSizeFetch, @Named(MpsLastProcessingTime) Date lastProcessingTime) In order to solve it, I am getting from the pre-initialized configuration the concrete Date as string, parse it using the format and bind specifically: bind(Date.class).annotatedWith(Names.named(MpsLastProcessingTime)).toInstance(parsedDate)); Is there a better way? Thanks -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Guice and Hadoop
Hey Eyal There's an old jira with a patch [1] to support Spring Beans, that replaces the ReflectionUtils class used to instantiate everything with a much proper object factory. But that issue was closes as won't fix saying that you can achieve similar behavior using Hadoop Configuration... but that way you'll use Guice much more like a service locator than anything else. This blog post [2] tells you how to use spring with regular config. Spring Hadoop looks promising! But it seems that DI support will come after 1.0 release... I'll look how the implement DI with current Hadoop API hope this helps, jordi [1] https://issues.apache.org/jira/browse/HADOOP-3261 [2] http://esammer.blogspot.com/2009/09/map-reduce-and-dependency-injection.html On Wed, Dec 28, 2011 at 6:13 PM, egolan egola...@gmail.com wrote: Hi everyone, Is there some documentation regarding integration of Guice and Hadoop. I am actually a newbie with Hadoop and have some experience with Spring. There is the Spring-Data project, which looks too much for what I want and need. Does anyone have experience with Guice and Hadoop? Can I find some good documentation for it? Thanks, Eyal -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Guice and Hadoop
can you share the thread url? i can't find it On Fri, Dec 30, 2011 at 6:33 PM, Owen O'Malley omal...@apache.org wrote: I replied over on the Hadoop lists, but your task should just create the injector in the setup method. -- Owen On Dec 30, 2011, at 3:00 AM, egolan egola...@gmail.com wrote: Thanks. I am going to migrate a full scale java app that calculates massive amount of data into a Hadoop process. So I am just starting experimenting with the MR. I am also practicing the DI concept in our architecture and this is why I went into Guice (my preferable choice over Spring). So I was wondering how to integrate them both. On Dec 30, 12:41 pm, jordi jo...@donky.org wrote: Hey Eyal There's an old jira with a patch [1] to support Spring Beans, that replaces the ReflectionUtils class used to instantiate everything with a much proper object factory. But that issue was closes as won't fix saying that you can achieve similar behavior using Hadoop Configuration... but that way you'll use Guice much more like a service locator than anything else. This blog post [2] tells you how to use spring with regular config. Spring Hadoop looks promising! But it seems that DI support will come after 1.0 release... I'll look how the implement DI with current Hadoop API hope this helps, jordi [1]https://issues.apache.org/jira/browse/HADOOP-3261 [2] http://esammer.blogspot.com/2009/09/map-reduce-and-dependency-injecti... On Wed, Dec 28, 2011 at 6:13 PM, egolan egola...@gmail.com wrote: Hi everyone, Is there some documentation regarding integration of Guice and Hadoop. I am actually a newbie with Hadoop and have some experience with Spring. There is the Spring-Data project, which looks too much for what I want and need. Does anyone have experience with Guice and Hadoop? Can I find some good documentation for it? Thanks, Eyal -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: creating a community of 3rd parties integrations
Hey! That sounds like a fantastic idea to me. A lot of times is hard to start some nice integration thinking that's just one person effort. And you're not sure about if there's any real need to do that. Taken Simone's example, it would be great to have a JUnit integration driven by the community needs. If we can join forces around 3rd party integrations I believe big things will happen! have a nice day, jordi On Thu, Nov 17, 2011 at 10:12 AM, Simone Tripodi simonetrip...@apache.orgwrote: Hi Daniel, the main issue I see indeed is that efforts are defragmented - just take a look at JUnit integrations frameworks - so the idea is moving all people under an umbrella that encourage a *community* development: it is not just moving the code and share ideas, is letting the community actively participate in the development. I really hope that other people will join us and move that discussion on the ASF Incubator. All the best! Simo http://people.apache.org/~simonetripodi/ http://simonetripodi.livejournal.com/ http://twitter.com/simonetripodi http://www.99soft.org/ On Wed, Nov 16, 2011 at 10:51 PM, Daniel Manzke daniel.man...@googlemail.com wrote: Hi, I just can say: I'm totally with you Simon! I really love Guice and my extension (Automatic Binding for Guice) is also listed. I saw a lot of interests in this extension and I would be happy, to share the code, the ideas, the future, ... with more people. The problem of the most extensions is, that it is developed by just one person. that's why the adoption is not how it should be. Would be interested what the others are thinking. Bye, Daniel -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Customising java.util.Logger
I think Modules.override would do the trick, use it in one of your modules: Modules.override(new AbstractModule() { @Override protected void configure() { // do whatever you need with your Logger bind(Logger.class)... } }); You can read more in Modules javadochttp://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/util/Modules.html#override(java.lang.Iterable? extends com.google.inject.Module) hth, jordi On Thu, Nov 17, 2011 at 1:16 PM, Moandji Ezana mwa...@gmail.com wrote: Hi, In introducing Guice to a project, I discovered that there's a built-in binding to j.u.Logger. I would like to customise the Logger's Formatter and FileHandlers. Is there a way I can either intervene before the Logger is injected, or override the built-in java.util.Logger binding? Thanks, Moandji -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Yet another Guice+Quartz integration
great job! i'm looking forward to use it in my code, thanks for sharing that jordi On Wed, May 4, 2011 at 5:38 PM, Simone Tripodi simonetrip...@apache.orgwrote: Hi all guys, after Terracotta announced the new Quartz API release, I started working on GitHub on a new implementation of Guice+Quartz integration, based on the previous version that Nino Martinez Wael and I did on GoogleCode. APIs are simple, all users have to do is plugging a QuartzModule in the Guice.createInjector() method and specify their scheduling: {code} Guice.createInjector(..., new org.nnsoft.guice.guartz.QuartzModule() { @Override protected void schedule() { ... scheduleJob(com.acme.MyJobImpl.class).withCronExpression(0/2 * * * * ?); // see javadoc APIs to see more options ... } }); {code} or using implicit scheduling: {code} @javax.inject.Singleton @org.nnsoft.guice.guartz.Scheduled(jobName = test, cronExpression = 0/2 * * * * ?) // see javadoc APIs to see more parameters public class com.acme.MyJobImpl implements org.quartz.Job { @javax.inject.Inject private MyCustomService service; public void execute(JobExecutionContext context) throws JobExecutionException { service.customOperation(); } } {code} Then, when creating the Injector instance: {code} Guice.createInjector(..., new org.nnsoft.guice.guartz.QuartzModule() { @Override protected void schedule() { ... scheduleJob(com.acme.MyJobImpl.class); ... } }); {code} And the magic happens! The scheduler will be launched and Job scheduled, that's all :) For those interested, they can find documentation on gh-pages branch[1] or on the GitHub space[2]. Feedbacks/suggestions/participation is open, just ping directly Nino or me, we would much more than glad to share your thoughts!!! Have a nice day, enjoy, Simo [1] http://99soft.github.com/guartz/userguide.html [2] https://github.com/99soft/guartz/ http://people.apache.org/~simonetripodi/ http://www.99soft.org/ -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Cannot use optimized @Assisted provider outside the scope of the constructor. (This should never happen. If it does, please report it.)
I've opened (finally) an issue with a testcase for this: http://code.google.com/p/google-guice/issues/detail?id=594 http://code.google.com/p/google-guice/issues/detail?id=594keep up your amazing job with guice! jordi On Tue, Jan 18, 2011 at 6:41 PM, Sam Berlin sber...@gmail.com wrote: Ya.. if you could open an issue, and even better: attach a testcase that reproduces it. Thanks! sam On Tue, Jan 18, 2011 at 4:05 AM, jordi jo...@donky.org wrote: Hey there! I'm using Guice-rc2 and I found this error using Assisted Inject... but the strange thing is that only happens when I bootstrap the injector with Stage.PRODUCTION This is what i'm doing: public interface Mailer {} public class SmtpMailer implements Mailer { @Inject public SmtpMailer(@Assisted MailConfig config) { ... } } The module config: install(new FactoryModuleBuilder() .implement(Mailer.class, SmtpMailer.class) .implement(Mailer.class, Simple.class, SimpleSmtpMailer.class) .build(MailerFactory.class)); And then I'm injecting the MailerFactory to get the instance: factory.create(gappsConfig); Do you want me to open an issue? hth, guice is truly amazing jordi -- Here's the full stacktrace: com.google.inject.CreationException: Guice creation errors: 1) Error in custom provider, java.lang.IllegalStateException: Cannot use optimized @Assisted provider outside the scope of the constructor. (This should never happen. If it does, please report it.) at com.eventuo.mail.MailerFactory.create(MailerFactory.java:1) while locating com.eventuo.mail.MailConfig annotated with @com.google.inject.assistedinject.Assisted(value=) for parameter 0 at com.eventuo.mail.SmtpMailer.init(SmtpMailer.java:38) at com.eventuo.mail.MailerFactory.create(MailerFactory.java:1) while locating com.eventuo.mail.Mailer annotated with interface com.google.inject.assistedinject.Assisted at com.google.inject.assistedinject.FactoryProvider2.initialize(FactoryProvider2.java:538) at com.google.inject.assistedinject.FactoryModuleBuilder$1.configure(FactoryModuleBuilder.java:315) 1 error at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:416) at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:175) at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109) at com.google.inject.Guice.createInjector(Guice.java:95) at com.google.inject.Guice.createInjector(Guice.java:83) at com.eventuo.test.GuiceJUnitRunner.createInjector(GuiceJUnitRunner.java:35) at com.eventuo.test.GuiceJUnitRunner.createTest(GuiceJUnitRunner.java:25) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:258) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:255) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.IllegalStateException: Cannot use optimized @Assisted provider outside the scope of the constructor. (This should never happen. If it does, please report it.) at com.google.inject.assistedinject.FactoryProvider2$ThreadLocalProvider.initialValue(FactoryProvider2.java:675) at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:141) at java.lang.ThreadLocal.get(ThreadLocal.java:131) at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40) at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38) at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62
Re: configure Singleton
Maybe @Provides will handle this for you? @Provides @Singleton public MaxBoundSet providesMaxBoundSet() { // instantiate the way you need return maxBoundSet; } http://code.google.com/p/google-guice/wiki/ProvidesMethods hth, jordi On Sun, Dec 12, 2010 at 1:02 AM, Peter tableyourt...@googlemail.com wrote: Hi, I know this 'singleton' problem was asked a lot of times here* but I would like to know the following specific case which wasn't answered. If I am doing: bind(MaxBoundSet.class).in(Singleton.class); all is fine except that I need to configure the MaxBoundSet singleton before instantiation. How would you do that? I don't like the idea to create a new subclass just for this config purpose. If I am doing: bind(MaxBoundSet.class).toInstance(new MaxBoundSetString(30, 60).setMaxAge(10 * 60 * 1000)); guice (2.0 with warp persist) does not use this instance. Instead it uses the default constructor to construct a new instance. Or am I doing a mistake if thats not working? Regards, Peter. * http://groups.google.com/group/google-guice/browse_thread/thread/21f3b72d9b86422b/a89eefb6ed54b06e?#a89eefb6ed54b06e http://groups.google.com/group/google-guice/browse_thread/thread/f03262830bd68419/b7fdf4e800caf98e?#b7fdf4e800caf98e http://groups.google.com/group/google-guice/browse_thread/thread/ed1b1fb9e963eb51/17a7bf99d49f8a5b?#17a7bf99d49f8a5b -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-gu...@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.comgoogle-guice%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-gu...@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Guice 3.0 RC1 Available
great job! I'm pretty happy that struts2 extension is back and fully operational! Just some minor bug: it doesn't appear in the current Javadoc API: http://google-guice.googlecode.com/svn/tags/3.0-rc1/javadoc/packages.html http://google-guice.googlecode.com/svn/tags/3.0-rc1/javadoc/packages.htmlI guess that's a mistake since it's back... thanks! jordi On Thu, Dec 9, 2010 at 2:16 PM, Sam Berlin sber...@gmail.com wrote: So long as it's clear that it's an RC and not the full release, I don't see how it could hurt having it in maven central. If you're able to do that, Stuart (preferably with the existing artifacts instead of a new build with potential, however minimal, differences), that would be awesome. sam On Thu, Dec 9, 2010 at 7:01 AM, Stuart McCulloch mccu...@gmail.comwrote: On 9 December 2010 10:44, Max Bowsher m...@f2s.com wrote: On 09/12/10 04:23, Sam Berlin wrote: All, Guice 3.0 RC1 is now available. Please see http://code.google.com/p/google-guice/wiki/Guice30 http://code.google.com/p/google-guice/wiki/Guice30 for links and details of what changed since Guice 2.0 (and since the last Guice 3.0 snapshot). That page also contains a broad overview of new features since the 2.0 release. The bottom of the page has some notes about compatibility issues if upgrading from Guice 2.0. Please give this RC a rigorous testing and report back to this list how it goes for you -- both positive and negative. With any luck, this will soon become an official release of Guice 3.0! Can we have this release candidate uploaded to the Maven Central Repository? let me know if you want help getting this onto Maven Central (either by uploading the existing artifacts or staging new artifacts for Maven via mvn deploy) That would *significantly* facilitate and encourage wider testing. Max. -- Cheers, Stuart -- You received this message because you are subscribed to the Google Groups google-guice-dev group. To post to this group, send email to google-guice-...@googlegroups.com. To unsubscribe from this group, send email to google-guice-dev+unsubscr...@googlegroups.comgoogle-guice-dev%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-guice-dev?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-gu...@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.comgoogle-guice%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-gu...@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: New Guice 3.0 Snapshot
Where's Struts 2 Extension? It's bundled in the .zip's but I can't find it in the Javadoc API pointed by Guice30 wiki or in the source code via Google Code source browser jordi On Wed, Nov 24, 2010 at 9:22 PM, Simone Tripodi simone.trip...@gmail.comwrote: sorry if I misunderstood, I thought you was trying to make a pure JSR330'ed implementation too :P BTW you gave me a reply, thanks :) Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Wed, Nov 24, 2010 at 7:34 PM, Adrian Cole fernc...@gmail.com wrote: I guess I should underscore something :) We aren't limited by guice impl of 330 doesn't suggest we are not limited by 330 :) The JSR 330 spec is extremely limited, although it does keep most vendor injection annotations out of mainstream code. I haven't seen any evidence of further development of that spec, and I haven't checked to see if JSR 299 (CDI) handles optional injection better. jclouds tries to minimize usage of optional inject, but it does exist in a few classes. As 330 is written, it is really hard to swap out implementations anyway. For example, the wiring logic of our spring java config example is quite different than guice, and doesn't flow the same way. CDI (at least weld) seems to flow slightly differently, too. Quite frankly, the impact of guice not releasing anything damages my time and effectiveness much more than 330 has ever helped. my 2p. -a On Wed, Nov 24, 2010 at 4:14 PM, Simone Tripodi simone.trip...@gmail.com wrote: Hi Adrian, thanks for your reply :) I'm interested on wich workaround you adopted for the @Inject(optional = true), can you point me please to some sources? Many thanks in advance! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Wed, Nov 24, 2010 at 4:10 PM, Adrian Cole fernc...@gmail.com wrote: Hi, Simone. One of the reasons jclouds really wants a guice release is that we've been jsr330ed for over a year now. There are holes in that spec like optional inject, but we are not limited by guice at the moment. Cheers, -Adrian On Nov 24, 2010 12:56 PM, Simone Tripodi simone.trip...@gmail.com wrote: Hi Adrian! :) for what I can see on jclouds revisions, you updated the new guice jars and ran existing code/tests using the new library, did you try to JSR330'ing the code? I'm asking because I found some issues, as I previously wrote, and I'd like to get feedbacks/ share experience also from other users. Please let me know, thanks in advance! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Wed, Nov 24, 2010 at 11:59 AM, AdrianCole fernc...@gmail.com wrote: +1 to release I've updated and tested jclouds with the current guice 3.0 snapshot. Cheers, -Adrian jclouds http://code.google.com/p/jclouds/issues/detail?id=413 On Nov 21, 12:27 am, Scott Hernandez scotthernan...@gmail.com wrote: How should we report the good/bad, well I know where to report the bad...? Just a response like this? I rolled out the newsnapshotand it works for me, no problems (in the first 3 minutes at least). On Sat, Nov 20, 2010 at 2:01 PM, Sam Berlin sber...@gmail.com wrote: All, I've uploaded a new guice 3.0snapshot. Please see http://code.google.com/p/google-guice/wiki/Guice30for new links and details of what changed since the lastsnapshot. Also see the rest of the page for a broad overview of new features since the 2.0 release, and the bottom of the page for notes about compatibility. Please let us know how it works for you -- both good and bad! Thanks! sam -- You received this message because you are subscribed to the Google Groups google-guice-dev group. To post to this group, send email to google-guice-...@googlegroups.com. To unsubscribe from this group, send email to google-guice-dev+unsubscr...@googlegroups.comgoogle-guice-dev%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-guice-dev?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-gu...@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.comgoogle-guice%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-gu...@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.comgoogle-guice%2bunsubscr...@googlegroups.com
Guice @ GTUG Barcelona
Hey there, if there's any Spaniards in this list maybe you're interested in the tech talk i made in GTUG Barcelona last weekend Here's the link (keynote in spanish): http://www.slideshare.net/giro9/dependency-injection-con-guice-gtug thanks! @jordi9 -- You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-gu...@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Re: Knowing the stage in a module
you can inject Stage in your classes too: @Inject public Foo(Stage stage) { this.stage = stage } On Tue, Sep 1, 2009 at 1:06 AM, Max Bowsher m...@f2s.com wrote: Pablo Fernandez wrote: Hi, I'd like to know the stage (PRODUCTION, DEVELOPMENT) that my injector is in. I basically want to do something like this boolean indentXml = Injector.CURRENT_STAGE != PRODUCTION bind(Boolean.class).annotatedWith(Names.named(xml.indent)).toInstance (indentXml); See AbstractModule#currentStage(). Max. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: tracking down a dependency path
hey there! i didn't try it but sure this helps you: http://code.google.com/p/google-guice/wiki/Grapher hope this helps jordi On 7/28/09, saltyazar ogu...@gmail.com wrote: hi all, first of all, thank you for the great contribution, keep up the good work! I am looking for a convenient way to track down a dependency path, created with Google Guice(GG). I am working on generated code and the developers used GG to inject dependencies. Now, I have thousands of line of code in front of me and I need something like an analysis tool, which (at best graphically) shows me how the dependency trees, created by GG, look like. Appreciate any help sltyzr --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: Issue 396 in google-guice: Struts2 plugin NPE if server bounced
I had a similar problem. When you're running with the new plugin, you can't set the guice.module property. comment that line on your .properties or XML and it would work. For unit tests i use the old plugin, since with the new one I got a NPE because i'm not creating the Servlet Context, just the Dispatcher. For doing that, conserve the old object factory creating another bean on struts-plugin.xml: bean type=com.opensymphony.xwork2.ObjectFactory name=guice class=com.google.inject.servlet.Struts2Factory/ bean type=com.opensymphony.xwork2.ObjectFactory name=guice-test class=com.google.inject.struts2.GuiceObjectFactory/ and switch your .properties when you start the Dispatcher, something like this: HashMapString, String params = new HashMapString, String(); // Override struts.xml config constants to use a guice test module params.put(struts.objectFactory, guice-test); params.put(guice.module, com.eventuo.guice.StrutsTestCaseModule); servletContext = new MockServletContext(); dispatcher = new Dispatcher(servletContext, params); dispatcher.init(); hope this helps! jordi On Mon, Jun 29, 2009 at 4:28 PM, Greg Lindholm greg.lindh...@gmail.comwrote: Is there any documentation for using this new Struts2 plugin? I see from the source that: The struts2 plugin no longer supports specifying a module + via the 'guice.module' property in XML. + Please install your module via a GuiceServletContextListener instead. This is unfortunate because I use this facility to swap in a test module when running unit tests. I create a Dispatcher and pass it the guice.module parameter to override the struts.xml value. Have you thought about how to unit test with this new plugin and how to provide a test module? Could you please include a note about this with the documentation. -- Forwarded message -- From: codesite-nore...@google.com Date: Fri, Jun 26, 2009 at 9:02 PM Subject: Issue 396 in google-guice: Struts2 plugin NPE if server bounced To: greg.lindh...@gmail.com Updates: Status: Fixed Comment #1 on issue 396 by dhanji: Struts2 plugin NPE if server bounced http://code.google.com/p/google-guice/issues/detail?id=396 Thanks for reporting this! Btw, note that I've rewritten the struts2 plugin altogether (it now works properly with Guice Servlet2 and it doesn't do evil things like catch Throwable). But I have made the fix in both versions of the plugin. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: G2 Struts 2 plugin exception
Thanks for the pacth! i was having this problem but i didn't have the time to debug it On Fri, Jun 19, 2009 at 10:41 PM, Greg Lindholm greg.lindh...@gmail.comwrote: Here is a patch which seems to work. Index: struts2/plugin/src/com/google/inject/struts2/ GuiceObjectFactory.java === --- struts2/plugin/src/com/google/inject/struts2/ GuiceObjectFactory.java (revision 1021) +++ struts2/plugin/src/com/google/inject/struts2/ GuiceObjectFactory.java (working copy) @@ -213,7 +213,9 @@ } public void destroy() { - delegate.destroy(); + if (delegate != null) { +delegate.destroy(); + } } public void init() { On Jun 19, 11:36 am, Greg Lindholm greg.lindh...@gmail.com wrote: I did a little debugging and found that this is pretty repeatable. It occurs if Tomcat is started then Stopped without any Guice activity happening. The 'delegate' member of com.google.inject.struts2.GuiceObjectFactory.ProvidedInterceptor gets created by the inject() method. If inject() is never called the destroy () method throws the NPE. destroy() needs to check if delegate is null before calling it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: @Inject always creating new object
hey there, you should define a @Singleton scope for you object. Guice by default creates a new object every time you request that object, that's called no scope. You could place the @Singleton annotation directly on MyObject class at type level, or in your TestModule bind the scope to your object: bind(MyObject.class).in(Scopes.SINGLETON); hope this helps! jordi On Fri, Jun 19, 2009 at 6:28 AM, Matt mter...@gmail.com wrote: I'm new to Guice, and I'm using injection within an interceptor, with requestInjection() in my module. The interceptor is being called just fine, so my module appears to be good. The problem is that @Inject is always creating a new object using the constructor for that object instead of injecting the original pre-initialized one. What am I missing here? public class TestInterceptor implements MethodInterceptor { @Inject MyObject obj; // always a newly-created object public Object invoke(...) { obj.doSomething(); ... } } public class TestImpl implements Test { @Inject MyObject obj; public TestImpl() { Injector injector = Guice.createInjector(new TestModule()); obj = injector.getInstance(MyObject.class); obj.init(); // I want access to this already initialized object in the interceptor } } Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: G2 and Struts2 plugin (problems)
not bogus... nice to know it before i replace new jars on my Struts2 apps ;P On 5/20/09, Greg Lindholm greg.lindh...@gmail.com wrote: Sorry, you can ignore the startup problem. Eclipse WTP didn't clean out the old jars from the deployment area so it had both the Guice 1.0 and 2.0 jars. Once I cleaned out the old jars It's starts up and runs fine. Sorry again for bogus post. On May 20, 1:36 pm, Greg Lindholm greg.lindh...@gmail.com wrote: I've been using Guice 1.0 with Struts 2.1.6 and the struts plugin. I just replaced the Guice 1.0 jars with the Guice 2.0 jars: guice-2.0.jar guice-struts2-plugin-2.0.jar guice-servlet-2.0.jar When I try to start my application (in Tomcat from Eclipse) I get: 2009-05-20 13:14:41,667 INFO com.opensymphony.xwork2.config.providers.XmlConfigurationProvider:31 - Parsing configuration file [struts-default.xml] 2009-05-20 13:14:41,866 INFO com.opensymphony.xwork2.config.providers.XmlConfigurationProvider:31 - Parsing configuration file [struts-plugin.xml] 2009-05-20 13:14:41,873 ERROR org.apache.catalina.core.ContainerBase. [Catalina].[localhost].[/nxm]:3639 - Exception starting filter struts2 Unable to load configuration. - bean - jar:file:/C:/Eclipse/ workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/ wtpwebapps/Allman%20Resolution%20v1/WEB-INF/lib/guice-struts2- plugin-2.0.jar!/struts-plugin.xml:11:63 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration (ConfigurationManager.java:58) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration (Dispatcher.java:360) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403) at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher (InitOperations.java:69) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init (StrutsPrepareAndExecuteFilter.java:48) at org.apache.catalina.core.ApplicationFilterConfig.getFilter (ApplicationFilterConfig.java:221) at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef (ApplicationFilterConfig.java:302) at org.apache.catalina.core.ApplicationFilterConfig.init (ApplicationFilterConfig.java:78) at org.apache.catalina.core.StandardContext.filterStart (StandardContext.java:3635) at org.apache.catalina.core.StandardContext.start (StandardContext.java:4222) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java: 1014) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java: 1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java: 443) at org.apache.catalina.core.StandardService.start (StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java: 700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) Caused by: Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:com.google.inject.struts2.GuiceObjectFactory - bean - jar:file:/ C:/Eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/ tmp1/wtpwebapps/Allman%20Resolution%20v1/WEB-INF/lib/guice-struts2- plugin-2.0.jar!/struts-plugin.xml:11:63 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register (XmlConfigurationProvider.java:222) at org.apache.struts2.config.StrutsXmlConfigurationProvider.register (StrutsXmlConfigurationProvider.java:101) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer (DefaultConfiguration.java:165) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration (ConfigurationManager.java:55) ... 22 more Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name guice has already been loaded by bean - jar:file:/C:/Eclipse/ workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/ wtpwebapps/Allman%20Resolution%20v1/WEB-INF/lib/guice-struts2- plugin-1.0.1.jar!/struts-plugin.xml:11:63 - bean - jar:file:/C:/ Eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/ wtpwebapps/Allman%20Resolution%20v1/WEB-INF/lib/guice-struts2- plugin-2.0.jar!/struts-plugin.xml:11:63 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register (XmlConfigurationProvider.java:206) ... 25 more May 20, 2009 1:14:45 PM
Re: Struts 2.1.6 + Guice 1.0
download the struts2 plugin version 1.0.1. http://google-guice.googlecode.com/files/guice-struts2-plugin-1.0.1.jar it should fix your problem! jordi On 4/28/09, ampyx ampyx...@gmail.com wrote: Hey guys, I am new to Guice 1.0. I was trying to integrate guice 1.0 with struts2.1.6. I got an error : java.lang.NullPointerException at com.google.inject.struts2.GuiceObjectFactory $ProvidedInterceptor.destroy(GuiceObjectFactory.java:214) at org.apache.struts2.dispatcher.Dispatcher.cleanup(Dispatcher.java: 287) at org.apache.struts2.dispatcher.FilterDispatcher.destroy (FilterDispatcher.java:233) at org.apache.catalina.core.ApplicationFilterConfig.release (ApplicationFilterConfig.java:332) at org.apache.catalina.core.StandardContext.filterStop (StandardContext.java:3744) at org.apache.catalina.core.StandardContext.stop(StandardContext.java: 4513) at org.apache.catalina.startup.HostConfig.checkResources (HostConfig.java:1108) at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1214) at org.apache.catalina.startup.HostConfig.lifecycleEvent (HostConfig.java:293) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent (LifecycleSupport.java:117) at org.apache.catalina.core.ContainerBase.backgroundProcess (ContainerBase.java:1337) at org.apache.catalina.core.ContainerBase $ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601) at org.apache.catalina.core.ContainerBase $ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610) at org.apache.catalina.core.ContainerBase $ContainerBackgroundProcessor.run(ContainerBase.java:1590) at java.lang.Thread.run(Unknown Source) There is no interceptor here, i guess the problem is due to this... Can any one help me with this problem pls? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: How do you bind to generics?
that's a java defect or not provided feature. instead use TypeLiteralhttp://google-guice.googlecode.com/svn/trunk/latest-javadoc/com/google/inject/TypeLiteral.html your code should be something like : TypeLiteralICacheNpc inpc = new TypeLiteralICacheNpc() {}; TypeLiteralCacheNpc npc = new TypeLiteralCacheNpc() {}; bind(inpc).to(npc); and similar for the other binding hope this helps! jordi On Tue, Apr 14, 2009 at 10:57 PM, aemami aemam...@gmail.com wrote: Hi, I am trying to accomplish the following: bind(ICacheNpc.class).to(CacheNpc.class); and bind(IMyMapperNpc.class).to(NpcMapper.class); This doesn't seem possible in Java, or is it? Keep in mind I'm not a java guy, I'm used to using Ninject (which was patterned after Google Guice) and C#. Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: Guice 2 prerelease snapshot 20090205
there's a lot more documentation on google code site: http://code.google.com/p/google-guice/wiki/Changes20 btw, thanks jesse and all of you bringing in all this new documentation! On Mon, Feb 9, 2009 at 11:32 AM, alexander.gruenew...@googlemail.com alexander.gruenew...@googlemail.com wrote: It's great to see progress. It would be also nice to see documentation of the new features in Guice's user guide. Are there any plans for this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: Google Guice Peformance: CPU and Memory
I'm having similar problems using Guice with Struts 2 + Hibernate. I dunno if Guice is part of the problem, when the PermGen error appears always is related to C3P0 pool created by Hibernate and the Logger stuff. jordi On Tue, Nov 25, 2008 at 7:41 PM, Dhanji R. Prasanna [EMAIL PROTECTED]wrote: Looks like a permgen space problem. The additional 90MB sounds about right. It's just the old classloader is not being garbage collected because something is being held on to from a different classloader. This problem is difficult to track down. Dhanji. On Tue, Nov 25, 2008 at 10:17 AM, Pablo Ruggia [EMAIL PROTECTED] wrote: For Guice and memory leaks, there is an interesting thread here: http://www.mail-archive.com/google-guice@googlegroups.com/msg00506.html Also I heard a lot of times that webapps leaking memory on redeploys are caused by commons logging, you can take a look here: http://wiki.apache.org/jakarta-commons/Logging/FrequentlyAskedQuestions Cheers ! On Tue, Nov 25, 2008 at 3:59 PM, o_swas [EMAIL PROTECTED] wrote: Hello, I've been reading up on Guice quite a bit and I like what I see. Great work, Google! Like lots of folks we currently use Spring for DI, in addition to transaction management for Hibernate. We have an application that is fairly large (large for us, anyways) and has lots of Hibernate objects and Spring-based service beans. The application is deployed to Glassfish v2. One continuing issue we have with this setup is a memory leak that occurs when ever we redeploy the application. The application is deployed, but when we redeploy the application (without restarting Glassfish) memory usage increases by 90+ MB. After a few redeploys, Glassfish runs out of memory and needs to be restarted. Note that the application *does not* leak memory while it's running; it's only during redeploys that memory leaks. While I'm sure we have some of our in-house written code is to blame, I've long suspected that possibly Hibernate (due to the dynamic proxying that makes all the magic happen) and Spring are culprits in the memory leak. So, after explaining all this, here are my questions: 1. Can anybody comment on how efficient (or inefficient) Guice is with memory and CPU? Is Guice likely to have any better runtime performance than Spring, or use less memory during runtime? Will Guice start up any faster (or slower) than Spring? 2. Is there anything in Guice that might cause memory leaks in web application when the application is redeployed? I see Guice uses parts of CGLIB, which I know a few years ago caused some nasty memory leaks in Hibernate (which I've since been fixed, I believe). 3. In general, can anybody comment on overall runtime performance of Guice compared to Spring? We don't really have any performance problems now, but I always like to be on the lookout to improve where we can and before we *need* to because the app couldn't scale with usage. Many thanks to Google for offering Guice!! -Ryan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: Google Guice Peformance: CPU and Memory
Right now i'm restarting jordi's webapp server when changes happen. There's no doubt that's the easier thing to do, but for seconds you got a 403 on the main page. Just one server at this time... i'll do some fancy 403 twitter-style page and no problem with that. On Tue, Nov 25, 2008 at 8:27 PM, Dhanji R. Prasanna [EMAIL PROTECTED]wrote: On Tue, Nov 25, 2008 at 11:22 AM, jordi [EMAIL PROTECTED] wrote: ... Looking at the console log i see this message when redeploying: A C3P0Registry mbean is already registered. This probably means that an application using c3p0 was undeployed, but not all PooledDataSources were closed prior to undeployment. This may lead to resource leaks over time. Please take care to close all PooledDataSources. I guess i'll have to clean up some resources before reloading context.. Are you calling close() on the Hibernate SessionFactory? This is very important. Also I recommend just bringing down the appserver every time. This idea that webapps can be redeployed while the server remains up is a bit silly to me. Dhanji. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---
Re: Guice newbie question: creating N objects on-demand
i was about to tell you also about injecting ProviderDispatcherHandler when i saw Bob's solution.. I guess if you inject that provider you can't tell him about the Predictor, at least at construction time.. jordi On Thu, Oct 16, 2008 at 6:24 PM, Andrew Clegg [EMAIL PROTECTED]wrote: Okay... You took me by surprise a bit, I was expecting something based on ProviderDispatchHandler. Like injecting a ProviderDispatchHandler as one of the arguments to the Dispatcher constructor (or a setter). Have I got the wrong end of the stick? Is that not what Providers are meant for? Thanks, Andrew. 2008/10/16 Bob Lee [EMAIL PROTECTED]: Oh, Jesse also has AssistedInject which can help with this stuff, but I still like to kick it old school. He can tell you more. Bob On Thu, Oct 16, 2008 at 9:16 AM, Bob Lee [EMAIL PROTECTED] wrote: Assuming you need to inject stuff into DispatchHandler and you don't want Dispatcher to know about DispatchHandler's deps, here's how I would do it. public class Dispatcher { private final DispatchHandler.Factory handlerFactory; // package-private for unit testing @Inject Dispatcher(DispatchHandler.Factory handlerFactory) { this.handlerFactory = handlerFactory; } ... public boolean dispatch() { for(PredictorProfile predictor : predictors) { handlerFactory.newInstance(predictor).start(); } return true; } } public class DispatchHandler extends Thread { private DispatchHandler(PredictorProfile predictor, Dep1 d1, ...) { ... } ... public static class Factory { private final Dep1 d1; ... // package-private so we can unit test easily. @Inject Factory(Dep1 d1, ...) { ... } ... public DispatchHandler newInstance(PredictorProfile predictor) { return new DispatchHandler(predictor, d1, ...); } } } You could also use Builder instead of Factory depending on how you structure things. Needing this additional class is unfortunate but necessary unless we extend the language to better support this stuff. Bob On Thu, Oct 16, 2008 at 9:02 AM, Andrew Clegg [EMAIL PROTECTED] wrote: Hey folks, I'm just getting started with Guice (and DI in general). I have a question, hope it's not too dense. I have a method that looks something like this in its first incarnation (_predictors is a collection): public boolean dispatch() { for( PredictorProfile predictor : _predictors ) { Thread handler = new DispatchHandler( predictor ); handler.run(); } return true; } i.e. for each predictor that the object knows about, kick off a thread to process it, and then return. (The return true is just a placeholder for a proper status code later.) Now I've started to think Guicily, I don't like the look of that call to new. Everything else in this app so far is injected for me by Guice. What's the best pattern for this kind of situation? Thanks! Andrew. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups google-guice group. To post to this group, send email to google-guice@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~--~~~~--~~--~--~---