-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Weld-OSGi Integration bundle files
- Loading branch information
Showing
19 changed files
with
1,492 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...gi/core/integration/src/main/java/org/jboss/weld/environment/osgi/impl/WeldActivator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat Middleware LLC, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jboss.weld.environment.osgi.impl; | ||
|
||
import org.jboss.weld.bootstrap.api.SingletonProvider; | ||
import org.jboss.weld.environment.osgi.impl.integration.BundleSingletonProvider; | ||
import org.jboss.weld.environment.osgi.spi.CDIContainerFactory; | ||
import org.osgi.framework.BundleActivator; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.ServiceRegistration; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This is the {@link BundleActivator} of the Weld implementation bundle. | ||
* <p/> | ||
* It is responsible for providing a {@link CDIContainerFactory} service using Weld as CDI implementation. | ||
* | ||
* @author Mathieu ANCELIN - SERLI (mathieu.ancelin@serli.com) | ||
* @author Matthieu CLOCHARD - SERLI (matthieu.clochard@serli.com) | ||
*/ | ||
public class WeldActivator implements BundleActivator { | ||
|
||
private Logger logger = LoggerFactory.getLogger(WeldActivator.class); | ||
|
||
private CDIContainerFactory factory = new WeldCDIContainerFactory(); | ||
private ServiceRegistration reg = null; | ||
|
||
@Override | ||
public void start(BundleContext context) throws Exception { | ||
logger.debug("Weld implementation bundle for CDI-OSGi is starting ..."); | ||
SingletonProvider.initialize(new BundleSingletonProvider()); | ||
reg = context.registerService(CDIContainerFactory.class.getName(), factory, null); | ||
logger.debug("Weld implementation bundle for CDI-OSGi STARTED"); | ||
} | ||
|
||
@Override | ||
public void stop(BundleContext context) throws Exception { | ||
logger.debug("Weld implementation bundle for CDI-OSGi is stopping ..."); | ||
reg.unregister(); | ||
SingletonProvider.reset(); | ||
logger.debug("Weld implementation bundle for CDI-OSGi STOPPED"); | ||
} | ||
} | ||
|
153 changes: 153 additions & 0 deletions
153
...core/integration/src/main/java/org/jboss/weld/environment/osgi/impl/WeldCDIContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat Middleware LLC, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jboss.weld.environment.osgi.impl; | ||
|
||
import org.jboss.weld.environment.osgi.impl.integration.Weld; | ||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.ServiceRegistration; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.enterprise.event.Event; | ||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import org.jboss.weld.environment.osgi.api.events.InterBundleEvent; | ||
import org.jboss.weld.environment.osgi.impl.extension.CDIOSGiExtension; | ||
import org.jboss.weld.environment.osgi.impl.extension.ExtensionActivator; | ||
import org.jboss.weld.environment.osgi.spi.CDIContainer; | ||
|
||
/** | ||
* This is the {@link CDIContainer} implementation using Weld. | ||
* | ||
* @author Mathieu ANCELIN - SERLI (mathieu.ancelin@serli.com) | ||
* @author Matthieu CLOCHARD - SERLI (matthieu.clochard@serli.com) | ||
*/ | ||
public class WeldCDIContainer implements CDIContainer { | ||
|
||
private Logger logger = LoggerFactory.getLogger(WeldCDIContainer.class); | ||
|
||
private final Bundle bundle; | ||
private Weld container; | ||
private Collection<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>(); | ||
|
||
public WeldCDIContainer(Bundle bundle) { | ||
logger.debug("Creation of a new Weld CDI container for bundle {}", bundle); | ||
this.bundle = bundle; | ||
container = new Weld(bundle); | ||
} | ||
|
||
@Override | ||
public void setRegistrations(Collection<ServiceRegistration> registrations) { | ||
this.registrations = registrations; | ||
} | ||
|
||
@Override | ||
public Collection<ServiceRegistration> getRegistrations() { | ||
return registrations; | ||
} | ||
|
||
@Override | ||
public Bundle getBundle() { | ||
return bundle; | ||
} | ||
|
||
@Override | ||
public boolean shutdown() { | ||
logger.debug("Weld CDI container is shutting down for bundle {}", bundle); | ||
return container.shutdown(); | ||
} | ||
|
||
@Override | ||
public void fire(InterBundleEvent event) { | ||
logger.debug("Weld CDI container for bundle {} is firing an inter bundle event: {}", bundle, event); | ||
Long set = CDIOSGiExtension.currentBundle.get(); | ||
CDIOSGiExtension.currentBundle.set(bundle.getBundleId()); | ||
container.getEvent().select(InterBundleEvent.class, | ||
new ExtensionActivator.SpecificationAnnotation(event.type()), | ||
new ExtensionActivator.SentAnnotation()).fire(event); | ||
if (set != null) { | ||
CDIOSGiExtension.currentBundle.set(set); | ||
} else { | ||
CDIOSGiExtension.currentBundle.remove(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean initialize() { | ||
return container.initialize(); | ||
} | ||
|
||
@Override | ||
public boolean isStarted() { | ||
return container.isStarted(); | ||
} | ||
|
||
@Override | ||
public Event getEvent() { | ||
return container.getInstance().select(Event.class).get(); | ||
} | ||
|
||
@Override | ||
public BeanManager getBeanManager() { | ||
return container.getBeanManager(); | ||
} | ||
|
||
@Override | ||
public Instance<Object> getInstance() { | ||
return container.getInstance(); | ||
} | ||
|
||
@Override | ||
public Collection<String> getBeanClasses() { | ||
return container.getBeanClasses(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof WeldCDIContainer)) { | ||
return false; | ||
} | ||
|
||
WeldCDIContainer that = (WeldCDIContainer) o; | ||
|
||
if (bundle != null ? !bundle.equals(that.bundle) : that.bundle != null) { | ||
return false; | ||
} | ||
if (container != null ? !container.equals(that.container) : that.container != null) { | ||
return false; | ||
} | ||
if (registrations != null ? !registrations.equals(that.registrations) : that.registrations != null) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = bundle != null ? bundle.hashCode() : 0; | ||
result = 31 * result + (container != null ? container.hashCode() : 0); | ||
result = 31 * result + (registrations != null ? registrations.hashCode() : 0); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.