Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update osgi annotatations in communication #315

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions core/communication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
Expand All @@ -68,6 +76,18 @@

<build>
<plugins>
<!-- overwrites configuration from parent pom to disable SCR plugin -->
<!-- ToDo: remove me when all felix dependencies are removed -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<executions>
<execution>
<id>generate-scr-descriptor</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,25 @@

import com.cognifide.aet.communication.api.queues.JmsConnection;
import com.cognifide.aet.communication.api.queues.JmsEndpointConfig;
import java.util.Map;
import com.cognifide.aet.queues.configuration.DefaultJmsConnectionConf;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Component(immediate = true, metatype = true, description = "AET JMS Connection", label = "AET Default JMS Connection")
@Component(immediate = true)
public class DefaultJmsConnection implements JmsConnection {

private static final boolean SESSION_TRANSACTION_DEFAULT_SETTING = false;

@Property(name = "url", label = "brokerUrl", description = "URL of the broker, no trailing '/', see http://activemq.apache.org/uri-protocols.html", value = "failover:tcp://localhost:61616")
private String brokerURL;

@Property(name = "username", label = "username", description = "ActiveMQ username", value = "karaf")
private String username;

@Property(name = "password", label = "password", description = "ActiveMQ password", value = "karaf")
private String password;
private DefaultJmsConnectionConf config;

@Reference
private ConfigurationAdmin configurationAdmin;
Expand All @@ -66,20 +56,20 @@ public Connection getJmsConnection() {

@Override
public JmsEndpointConfig getEndpointConfig() {
return new JmsEndpointConfig(brokerURL, username, password);
return new JmsEndpointConfig(config.brokerURL(), config.username(), config.password());
}

@Activate
public void activate(Map properties) throws JMSException {
updateProperties(properties);
public void activate(DefaultJmsConnectionConf config) throws JMSException {
this.config = config;
connect();
}

public void connect() throws JMSException {
LOG.info("Connecting to broker {} on user {}", brokerURL, username);
final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerURL);
connectionFactory.setUserName(username);
connectionFactory.setPassword(password);
LOG.info("Connecting to broker {} on user {}", config.brokerURL(), config.username());
final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(config.brokerURL());
connectionFactory.setUserName(config.username());
connectionFactory.setPassword(config.password());
connectionFactory.setTrustAllPackages(true);
connection = connectionFactory.createConnection();
connection.start();
Expand All @@ -91,14 +81,8 @@ public void deactivate() {
}

public void disconnect() {
LOG.info("Disconnecting from broker {} on user {}", brokerURL, username);
LOG.info("Disconnecting from broker {} on user {}", config.brokerURL(), config.username());
JmsUtils.closeQuietly(connection);
}

private void updateProperties(Map<String, ?> stringDictionary) {
username = (String) stringDictionary.get("username");
password = (String) stringDictionary.get("password");
brokerURL = (String) stringDictionary.get("url");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* 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 com.cognifide.aet.queues.configuration;

import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

@ObjectClassDefinition(name = "AET JMS Connection", description = "AET JMS Connection")
public @interface DefaultJmsConnectionConf {

String DEFAULT_BROKER_URL_PARAM = "failover:tcp://localhost:61616";

String DEFAULT_USERNAME_PARAM = "karaf";

String DEFAULT_PASSWORD_PARAM = "karaf";

@AttributeDefinition(
name = "brokerUrl",
description = "URL of the broker, no trailing '/', see http://activemq.apache.org/uri-protocols.html",
type = AttributeType.STRING)
String brokerURL() default DEFAULT_BROKER_URL_PARAM;

@AttributeDefinition(
name = "username",
description = "ActiveMQ username",
type = AttributeType.STRING)
String username() default DEFAULT_USERNAME_PARAM;

@AttributeDefinition(
name = "password",
description = "ActiveMQ password",
type = AttributeType.STRING)
String password() default DEFAULT_PASSWORD_PARAM;

}
21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@
</dependency>

<!-- osgi -->

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
Expand Down Expand Up @@ -668,7 +687,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.1.1168</version>
<version>3.4.1.1168</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down