Coder Social home page Coder Social logo

hk2's Introduction

⚠️This project is now part of the EE4J initiative. This repository has been archived as all activities are now happening in the corresponding Eclipse repository. See here for the overall EE4J transition status.


hk2

A light-weight and dynamic dependency injection framework

hk2's People

Contributors

ankathur avatar avalez avatar fabriziocucci avatar glassfishrobot avatar japod avatar jwells131313 avatar jwgish avatar lanxx019 avatar ljnelson avatar mtau11 avatar muter avatar romain-grecourt avatar stevetodd avatar sumauppa avatar yaminikb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hk2's Issues

Add API for custom injection point annotations.

Currently to support custom injection point annotations (e.g. JAX-RS @context, @PathParam ...) it is necessary to use non-public InjectionResolver API.
Proposed solution is to move the IR interface into a public API package and document it properly.

Affected Versions

[2.1.*]

Inhabitant.get tries to instantiate instead of retrieving the existing once if PostConstruct isn't implemented

Trying to get EmbeddedWebContainer (Singleton Scope) instance by using
Inhabitant.get() gives me "Failed to create class
com.sun.enterprise.web.EmbeddedWebContainer". It seems that Inhabitant.get() is
trying to instantiate com.sun.enterprise.web.EmbeddedWebContainer instead of
retrieving the existing one. The workaround is to have EmbeddedWebContainer
implement PostConstruct. The instance correctly retrieved using
Inhabitant.get() after PostConstruct implementation.

Embedded embedded = (org.apache.catalina.startup.Embedded)embeddedInhabitant.get();

@service(name="com.sun.enterprise.web.EmbeddedWebContainer")
@Scoped(Singleton.class)
public final class EmbeddedWebContainer extends Embedded implements PostConstruct {

Environment

Operating System: All
Platform: Macintosh

Affected Versions

[1.*]

JSR330 constructor injection does not work

After modifying one of the hk2 jsr330 integration module unit tests (see the attached patch), the constructor injection obviously doesn't work. It's just not clear whether the issue is related to the Hk2Runner test runner or the jsr330 integration as such.

To reproduce:
1. download attached patch & apply
2. run the patched test (test fails)

Affected Versions

[1.*]

Documentation

Please provide us better documentation: High Level Design, JavaDoc and code
comments. Thanks.

Environment

Operating System: All
Platform: All

Affected Versions

[1.*]

Installing metro when server is running does not resolve the dependencies

Try starting the v3 server run admingui or UC and install metro you will get
unresolved bundle errors This needs server restart
This is evaluation from Sahoo
"I just checked the code and compared with the exception stack. I was wrong in
my earlier email. Even though UC does not call any OSGi API, when new modules
are copied to modules directory, one of the HK2 threads detects them immediately
and calls appropriate OSGi API to resolve them, but it does not take care of the
dependencies among newly added modules, so it is getting that exception. It is a
bug in HK2; too late to fix. Restarting the server is a work around. I should
also say that despite the log message, the rest of the functionality should
continue to work as usual, only the newly added modules won't be available until
server is restarted. "

Environment

Operating System: All
Platform: All

Affected Versions

[1.*]

Guice integration.

HK2 needs to be able to delegate injection to Guice.

Affected Versions

[2.1.*]

FactoryFor should be automatically applied

Consider this code

@service
@factoryfor(DomainMBean.class)
public class DomainMBeanAccess implements ConextualFactory {
...
}

The FactoryFor declaration and use of generics makes this have redundant definitions that can also lead to mismatches / errors.

I propose that the inhabitant generation infrastructure is made aware to look for generics so that FactoryFor becomes optional and implicitly defined, required only in cases where the generic form is not used (i.e., defaulting to Object).

I further would like to see a level of validation that if they are both used, and inconsistent with one another than an error is generated.

Affected Versions

[2.1.*]

Listing CRUD subelements of a not-yet-existing element seems to confuse subsequent list commands

In GlassFish, SecureAdmin is defined this way (with other, irrelevant details omitted here):

@configured
/**

  • Represents the admin security settings for the domain.
    *
    */
    public interface SecureAdmin extends ConfigBeanProxy, Injectable {

@element
@create(value="enable-secure-admin-principal", decorator=SecureAdminPrincipal.CrDecorator.class, i18n=@i18n("enable.secure.admin.principal.command"))
@delete(value="disable-secure-admin-principal", resolver=SecureAdminPrincipal.Resolver.class, i18n=@i18n("disable.secure.admin.principal.command"))
@Listing(value="list-secure-admin-principals", i18n=@i18n("list.secure.admin.principals.command"))
public List getSecureAdminPrincipal();

@element
@create(value="enable-secure-admin-internal-user", decorator=SecureAdminInternalUser.CrDecorator.class, i18n=@i18n("enable.secure.admin.internal.user.command"))
@delete(value="disable-secure-admin-internal-user", resolver=TypeAndNameResolver.class, i18n=@i18n("disable.secure.admin.internal.user.command"))
@Listing(value="list-secure-admin-internal-users", i18n=@i18n("list.secure.admin.internal.user.command"))
public List getSecureAdminInternalUser();

Note that SecureAdmin is not annotated with @NotNull.

If I start the server in a newly-created domain (for which domain.xml contains no element), then run

asadmin list-secure-admin-principals

I get the expected empty results.

Next I run

asadmin enable-secure-admin-principal me

The domain.xml contains what I expect:

But if I run

asadmin list-secure-admin-principals

again I still get an empty list. Yet I can successfully run

asadmin disable-secure-admin-principal me

and it finds it and removes it.

On the other hand, if after the server start-up I do this

asadmin enable-secure-admin-principal me
asadmin list-secure-admin-principals

then the output contains an entry for "me" as expected.

It is as if the element is missing when the first "list" command runs, then the in-memory configuration is convinced that the element will never appear.

By the way, once I restart the server after doing the start/list/enable sequence then the list command works correctly.

Affected Versions

[2.1.*]

Services.forContract(...).all() returns duplicate entries.

Un-ignore the testAllContractBindingsRetrieval() unit test in org.glassfish.hk2.tests.basic.BasicInjectionTests to reproduce the issue. Initial investigation points at a potential bug in ContractLocatorImpl.all(boolean) which does not filter out duplicate entries.

Affected Versions

[1.*]

Modular binding & injection API

This is an umbrella RFE for programmatic injection API. It covers e.g.

  • defining custom static injection bindings (grouped into modules)

  • defining custom injection bindings dynamically (to an existing Injector or Services)

  • defining custom injection providers (factories) that are (potentially) context-aware

  • defining custom injection point annotations (i.e. @Inject substitution)

  • defining custom injection scopes

  • performing class & instance-based injection

  • performing method parameter injection, i.e. return the injected values for parameters of a method

Affected Versions

[2.1.*]

bean constraint violation error during upgrade

Testing GlassFish V3.1 b32

Performed and upgrade of cluster profile of V2.1.1 with 2 deployed apps to V3.1.

The following error is in upgrade.log:

asadmin: SEVERE: class com.sun.hk2.component.LazyInhabitant upgrading domain.xml failed java.lang.RuntimeException: org.jvnet.hk2.config.TransactionFailure: Constraints for this bean violated.
asadmin: Message = gmsMulticastAddress may not be nullgmsMulticastPort may not be null
asadmin: Dec 8, 2010 12:10:24 PM com.sun.enterprise.v3.admin.cluster.SecureAdminConfigUpgrade postConstruct

The folloiwng occurs in DAS server.log

[#|2010-12-08T12:10:25.538-0500|SEVERE|null|javax.enterprise.system.core.com.sun.enterprise.server.logging|_ThreadID=22;_ThreadName=Thread-1;|This message was emitted before the logging service started:class com.sun.hk2.component.LazyInhabitant upgrading domain.xml failed java.lang.RuntimeException: org.jvnet.hk2.config.TransactionFailure: Constraints for this bean violated.
Message = gmsMulticastAddress may not be nullgmsMulticastPort may not be null|#]

Affected Versions

[2.1.*]

HK2 removes "listeners" when it should remove "listener"

It seems that there is clerical error in com.sun.enterprise.module.common_impl.
AbstractRepositoryImpl.java around line 225.The origin code is like this:
public synchronized boolean removeListener(RepositoryChangeListener listener)
{
if (listeners==null)

{ return false; }

return listeners.remove(listeners);
}

I think the last statement in the method should be changed to �return
listeners.remove(listener);“
I checked both 0.3.32-prelude-b28 and the trunk version,the bug exists in
both versions.
If this is not a bug or it has been corrected, forgive my innocence,

Environment

Operating System: All
Platform: All

Affected Versions

[1.*]

auto-depends-plugin is not compatible with Java 7

Compiling a hk2-jar project fails on Java 7 complaining that com.sun.mirror.apt.AnnotationProcessorFactory cannot be loaded by Maven.
Tracking down the issue shows a

default-tools.jar


java.vendor
Oracle Corporation<!-Sun Microsystems Inc.->




com.sun
tools
1.4.2
system
$

{java.home}

/../lib/tools.jar




block in
auto-depends-plugin [apt]

Changing the value to Oracle Corporation allows to compile again.

Environment

Java 7 (b135)
Windows 7

Affected Versions

[2.1.*]

@Inject @Named("name") Provider<Foo> doesn't work

When multiple implementations of a contract exist for a contract (say Foo), then

@Inject
@nAmed("some-name")
Provider fooProvider;

doesn't work.

The injected provider is not null but fooProvider.get() returns an object that doesn't match the name. Seems like name specified in @nAmed is ignored

Affected Versions

[2.1.*]

StackOverflowError injecting circular dependencies

java.lang.StackOverflowError
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.j
at java.lang.reflect.Constructor.newInstance(Constructor.java
at java.lang.Class.newInstance0(Class.java
at java.lang.Class.newInstance(Class.java
at com.sun.hk2.component.ConstructorWomb.create(ConstructorWomb.java
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java
at
com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java
at org.jvnet.hk2.component.Habitat.getComponent(Habitat.java
at com.sun.hk2.component.AbstractWombImpl$1.getValue(AbstractWombImpl.java
at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java

Using PostConstruct causes another StackOverflowError:
java.lang.StackOverflowError
at
sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignatureParser.java
at
sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java
at
sun.reflect.generics.parser.SignatureParser.parseTypeSignature(SignatureParser.java
at
sun.reflect.generics.parser.SignatureParser.parseTypeSig(SignatureParser.java
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java
at
sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java
at
sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java
at
sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java
at java.lang.reflect.Field.declaredAnnotations(Field.java
at java.lang.reflect.Field.getAnnotation(Field.java
at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java
at
com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java
at org.jvnet.hk2.component.Habitat$1.get(Habitat.java
at java.util.AbstractList$Itr.next(AbstractList.java
at java.util.AbstractCollection.toArray(AbstractCollection.java
at com.sun.hk2.component.AbstractWombImpl$1.getValue(AbstractWombImpl.java
at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java
at
com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java
at org.jvnet.hk2.component.Habitat.getComponent(Habitat.java
at com.sun.hk2.component.AbstractWombImpl$1.getValue(AbstractWombImpl.java
at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java
at
com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java
at org.jvnet.hk2.component.Habitat.getByContract(Habitat.java

Environment

Operating System: All
Platform: Sun
URL: https://glassfish.dev.java.net/issues/show_bug.cgi?id=8560

Affected Versions

[1.*]

Spring integration.

HK2 needs to be able to delegate injection to Spring.

Affected Versions

[2.1.*]

NPE during config change

An NPE aborts notification of config change listeners.

[#|2010-11-19T23:51:36.622-0600|SEVERE|glassfish3.1|LogStrings.org.glassfish.javaee.services|_ThreadID=17;_ThreadName=Thread-1;|RAR9607:
Error while handling Change event.
java.lang.NullPointerException
at org.jvnet.hk2.config.ConfigBeanProxy$Duck.getParent(ConfigBeanProxy.java:111)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jvnet.hk2.config.Dom.invokeDuckMethod(Dom.java:943)
at org.jvnet.hk2.config.Dom.invoke(Dom.java:896)
at
org.glassfish.config.support.TranslatedConfigView.invoke(TranslatedConfigView.java:119)
at $Proxy21.getParent(Unknown Source)
at
org.glassfish.javaee.services.ResourceManager$PropertyChangeHandler.handleChangeEvent(ResourceManager.java:370)
at
org.glassfish.javaee.services.ResourceManager$PropertyChangeHandler.changed(ResourceManager.java:318)
at org.jvnet.hk2.config.ConfigSupport.sortAndDispatch(ConfigSupport.java:329)
at org.glassfish.javaee.services.ResourceManager.changed(ResourceManager.java:265)
at
org.jvnet.hk2.config.Transactions$ConfigListenerJob.process(Transactions.java:376)
at
org.jvnet.hk2.config.Transactions$ConfigListenerJob.process(Transactions.java:366)
at
org.jvnet.hk2.config.Transactions$ConfigListenerNotifier$1$1.call(Transactions.java:256)
at
org.jvnet.hk2.config.Transactions$ConfigListenerNotifier$1$1.call(Transactions.java:254)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)

| #] |

Environment

Operating System: All
Platform: Macintosh

Affected Versions

[1.*]

add support for Long datatype to config

The valid dataTypes for config bean attributes are currently String, Boolean, Integer, and Character.

This RFE is for adding support for the Long datatype.

This effects at least the following file:
hk2/hk2/config/src/main/java/org/jvnet/hk2/config/WriteableView.java

This is desired for a new attribute in Grizzly, max-swallowing-input-bytes.

Affected Versions

[1.*]

JSR-330 support

  • support for JSR 330 annotations
  • support for JSR 330 Provider in HK2 binding API (to use it interchangeably with Factory)
  • support for JSR 330 Provider injection (to be able to inject it interchangeably with Factory)

Affected Versions

[2.1.*]

Ability to bind single class/factory/instance to multiple contracts.

Currently the following code

binderFactory.bind(ContractA.class).to(Service.class);
  binderFactory.bind(ContractB.class).to(Service.class);

or

binderFactory.bind(ContractA.class).toFactory(ServiceFactory.class).in(SomeScope.class);
  binderFactory.bind(ContractB.class).toFactory(ServiceFactory.class).in(SomeScope.class);

results in 2 separate instances of Service/ServiceFactory class being constructed to resolve the injection of ContractA or ContractB respectively.

While sometimes this may be desired, more often the scenario requires that both ContractA as well as ContractB are resolved using just the same single instance of Service/ServiceFactory class in a given scope.

Resolving the problem with the current API is currently not intuitive and error prone.

Affected Versions

[2.1.*]

Null produced by a factory is not treated as a valid scoped value.

In certain cases (with e.g. optional injection) it is possible that an instance factory may want to return null for a certain scope. Currently however the 'null' value is not treated as a valid value stored in a scope, instead it is used in the decision logic that will try to invoke the instance factory again.

The 'null' value returned by the ScopeInstance should not be automatically treated as if no instance value has been stored in the scope. It may be that the null value IS the actual value stored in the given scope instance.

Affected Versions

[2.1.*]

Add/document custom scopes support

It's not clear how to properly support scoping annotations (annotated with javax.inject.Scope) and how to link them with proper scope implementations. E.g. how to define a link between custom RequestScope scope class and @RequestScoped scoping annotation?

Affected Versions

[2.1.*]

Request for improvements in debugging dependency problems in systems using HK2

After spending some time tracking down some dependency issues in GlassFish 3.1, it seems like a little debugging help from HK2
would be very useful.

First, there are situations when injection fails due to a failure at some point in a chain of dependencies. By dependency
I mean that component A depends on component B if A injects a reference to B. Injection fails if for some reason an
implementation of an @contract interface cannot be found. This is typically because no implementation can be found in the
classpath. The problem becomes more acute if there is a chain of such dependencies spanning multiple modules in a complex
system like GlassFish: A dependsOn B dependOn C dependsOn D. If no implementation of D can be found, then injection of
B and C will also fail. Typically this leaves code in A with a NullPointerException, and no idea why it was not injected.

I have two suggestions for possible assistance with this sort of problem in HK2:

1. Have an option that provides more information about failures to resolve dependencies. Seeing a path for the resolution
failure would be nice, but something a simple as a log message whenever a dependency cannot be resolved would be very
helpful.

2. Have an option that provides information about what jar files/class paths HK2 is using to search for
dependencies. mvn -X helps, but a more directly targeted option would speed debugging these problems.
This is particularly important for the maven surefire tests, because it is not obvious exactly what
is being scanned by HK2 (in GF 3.1, it's pretty obviously the modules directory).

Affected Versions

[2.1.*]

hard coded error message

There is a hard coded error message that shows in gf v3 aadmin gui. The message
need to be put in property file.
f (!isValid) {
String msg = "Validation Failed: " +
value + " is not of data type: " + al.dataType;
throw new ValidationException(msg);
}

Environment

Operating System: All
Platform: All

Affected Versions

[1.*]

CDI (or at least CDI impl in GF) integration

HK2 needs to be able to delegate injection to CDI provider. Generic support is preferrable, but GlassFish specific support would be good enough.

The typical use case for CDI / JAX-RS (Jersey) integration is a CDI bean (whose life-cycle is managed by CDI container) but is at the same time a JAX-RS resource that needs Jersey to satisfy the JAX-RS specific injection points. E.g.:

@SessionScoped   // <-- CDI managed @Path("foo/{id}")   // <-- JAX-RS resource public class FooResource {
    @Inject MyEjb ejb;    // <-- injection point resolved by CDI
    @Context UriInfo uriInfo;    // <-- injection point resolved by Jersey (via HK2) 
    ...
}

In the example above the FooResource needs to be managed by a CDI container and when Jersey tries to retrieve an instance of it via HK2 (e.g. via ServiceLocator.getService(FooResource.class)), the HK2 needs to recognize the bean is managed by an external container (CDI) and needs to retrieve it from that container.

Also, the HK2 needs to be able to register an CDI extension bean in the CDI container that will be able to resolve custom (in our case JAX-RS) injection points that were added to the HK2 ServiceLocator by Jersey.

In summary, the process of retrieval of an externally managed (CDI) component by Jersey via HK2 should look like:

  1. Jersey asks HK2 for a component instance
  2. HK2 does not have a descriptor so it consults the external provider(s) (in our case CDI) to provide the component instance
  3. External provider creates and injects the instance
    • During that phase external provider consults HK2 integration layer (in our case a CDI extension) to resolve the unsatisfied (JAX-RS/Jersey specific) injection points
  4. External provider returns the component to HK2
  5. HK2 passes the component to Jersey

Note that the above could be converted into a generic HK2 external component provider API that is not necessarily CDI specific, but could be reused to integrate other injection providers too (Spring, Guice, ...). Obviously I do not insist on this particular solution. The important part is the use case demonstrating the problem that we need to solve.

Affected Versions

[2.1.*]

Why is name thrown away?

From Habitat.java

// TODO: mutating Habitat after it's created poses synchronization issue
public void addComponent(String name, T component) throws ComponentException

{ add(new ExistingSingletonInhabitant(component)); }

==============

Why accept a name and then not use it?

Affected Versions

[1.*]

improve performance of inhabitants file parsing

A Jprofiler analysis of the GlassFish asadmin command, which uses HK2, shows that for a simple command (list-commands -x which just prints a usage message), asadmin spends almost 20% of its time in the InhabitantsParser.parse method. Closer examination of this method reveals several areas where performance improvements can be made.

For example, InhabitantsParser.parse calls Iterator.hasNext and Iterator.next at lines 158-159. These are actually calls to the KeyValuePairParser class. In KeyValuePairParser.parseNext, the first line is:

int del = Math.min(indexOf('='),indexOf(','));

This line performs two searches, potentially all the way to the end of the string looking for the two delimiters. Replacing this with a single iteration that looks for either character and stops when it finds one should be faster.

Also, the InhabitantsScanner creates an InhabitantFileBasedParser object for each line in the inhabitants file. The InhabitantFileBasedParser constructor calls InhabitantFileBasedParser.buildMetadata, which scans through the entire line. Later, the line is scanned again looking for the index information. These two scans could be combined into one, i.e., the search for indexes could use the meta data that was built by buildMetadata.

Affected Versions

[1.*]

hk2-maven-plugin appears to be incompatible with JDK7

Failure:

[INFO] Internal error in the plugin manager executing goal 'org.glassfish.hk2:hk2-maven-plugin:1.6.11:hk2-compile': Unable to load the mojo 'org.glassfish.hk2:hk2-maven-plugin:1.6.11:hk2-compile' in the plugin 'org.glassfish.hk2:hk2-maven-plugin'. A required class is missing: com/sun/mirror/apt/AnnotationProcessorFactory
com.sun.mirror.apt.AnnotationProcessorFactory

This can be worked around by adding the following dependency to the plugin definition in the pom:

com.sun tools 1.7.0 system $

{java.home}

/../lib/tools.jar

Once added, the project once again compiles, however the following warnings is printed:

warning: The apt tool and its associated API are planned to be
removed in the next major JDK release. These features have been
superseded by javac and the standardized annotation processing API,
javax.annotation.processing and javax.lang.model. Users are
recommended to migrate to the annotation processing features of
javac; see the javac man page for more information.

Affected Versions

[1.*]

hard coded bean validation constraints message

The following file has a hard coded message that is put into exception messages from Bean Validation errors. This hard coded message ends up in the command line output from GlassFish.

hk2/config/src/main/java/org/jvnet/hk2/config/WriteableView.java

The message is:

String msg = "Constraints for this bean " +
"violated. \n Message = ";

It shows up in two places in that file.

This message needs to be internationalized and localized. Also, the default English format of the message should get rid of the "=" sign in the message.

Another option would be to put the constraint violation messages into the ValidationException in such a way that the application code, i.e., GlassFish, can extract the messages so that they can be reformated by the application.

Affected Versions

[1.*]

invalid warning when injecting optional field and service is missing

Consider the following code:

@contract
public interface SomeContract

{...}

class Bar

{ @Inject(optional=true) SomeContract foo; }

When this is evaluated where there is no service that implements SomeContract (resulting in foo==null), the following warning is output to the log file:

[#|2011-08-26T05:43:08.646-0700|WARNING|glassfish3.2|org.jvnet.hk2.component.ContractLocatorImpl|_ThreadID=12;_ThreadName=admin-listener(1);|name and scope are currently only appropriate for byContract usage|#]

In InjectInjectionResolver.getValue, at line 117, the call to:

habitat.isContract(genericType)

is returning false. This is why the warning message is being printed.

It appears that in the Habitat class, the byContract list is only populated if some service actually implements the contract. So even if the genericType is a Contract, it will not be detected as a contract since there are no implementers of the contract.

Affected Versions

[1.*]

ModulesRegistry find module by package

While working on the JSF OSGi bundle integration, I've noticed
a small problem with how the jsf-connector module interacts
with HK2.

The current version of the jsf-connector has the jsf implementation
classes inlined. This allows the TLD provider to call ModulesRegistry(Class)
passing in the TLD provider class itself to locate the Module to get the TLD
locations.

However, once the jsf implementation classes are no longer inlined, the
code falls apart (the TLDs are in a separate module now). I've resolved
the issue by calling ModulesRegistry.getModules() and searching the
Collection for the module that needs to be scanned using the osgi symbolic
bundle name - probably not the best choice as we don't want any hard dependencies
on bundle names.

I've looked at the ModulesRegistry API and haven't found anything else that
we might be able to leverage. So I thought I would throw out an idea.
Since OSGi bundles typically have a list of packages they export, it seems a
module could potentially be found using a package name as well. Something
like:

Module ModulesRegistry.find(String packageName)

Environment

Operating System: All
Platform: All

Affected Versions

[1.*]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.