First working version

This commit is contained in:
2021-10-05 16:08:29 +02:00
commit caceed005d
14 changed files with 407 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
Bundle-Version: 1.0.0
Private-Package: com.thalesgroup.nl.chat.impl
-buildpath: \
osgi.core,\
org.osgi.service.component,\
org.osgi.service.component.annotations,\
org.osgi.service.remoteserviceadmin,\
com.thalesgroup.nl.chat.api;version=latest

View File

@@ -0,0 +1,35 @@
-runfw: org.apache.felix.framework
-runproperties: \
org.amdatu.remote.discovery.configured.endpoints='http://172.24.12.36:8080/org.amdatu.remote.discovery.configured,http://172.24.15.19:8080/org.amdatu.remote.discovery.configured,http://172.24.12.66:8080/org.amdatu.remote.discovery.configured,http://172.24.12.236:8080/org.amdatu.remote.discovery.configured,http://172.24.11.212:8080/org.amdatu.remote.discovery.configured,http://172.24.18.97:8080/org.amdatu.remote.discovery.configured,http://172.24.11.177:8080/org.amdatu.remote.discovery.configured,http://172.24.13.242:8080/org.amdatu.remote.discovery.configured,http://172.24.14.222:8080/org.amdatu.remote.discovery.configured,http://172.24.14.202:8080/org.amdatu.remote.discovery.configured',\
org.amdatu.remote.discovery.configured.host=172.24.11.212,\
org.amdatu.remote.admin.http.host=172.24.11.212,\
org.amdatu.remote.admin.http.port=8080,\
org.osgi.service.http.port=8080
-runfeatures: shell
-runbundles: \
org.apache.felix.gogo.command,\
org.apache.felix.gogo.runtime,\
org.apache.felix.gogo.shell,\
org.apache.felix.scr,\
org.osgi.util.promise,\
org.osgi.util.function,\
org.apache.felix.configadmin,\
org.apache.felix.configurator,\
org.apache.felix.cm.json,\
org.apache.sling.commons.johnzon,\
org.apache.felix.converter,\
org.amdatu.remote.admin.http,\
org.amdatu.remote.discovery.configured,\
org.amdatu.remote.topology.promiscuous,\
org.apache.felix.metatype,\
org.apache.felix.eventadmin,\
org.apache.felix.log,\
org.apache.felix.dependencymanager,\
org.apache.felix.http.servlet-api,\
org.apache.felix.http.jetty,\
org.osgi.service.remoteserviceadmin,\
com.thalesgroup.nl.chat.api;version=latest,\
com.thalesgroup.nl.chat.impl;version=latest

View File

@@ -0,0 +1,17 @@
package com.thalesgroup.nl.chat.impl;
import com.thalesgroup.nl.chat.api.Chat;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.remoteserviceadmin.RemoteConstants;
@Component(
property = {RemoteConstants.SERVICE_EXPORTED_INTERFACES + "=com.thalesgroup.nl.chat.api.Chat",
"participant.name=Bas"}
)
public class ChatImpl implements Chat {
@Override
public void sendMessage(String author, String message){
System.out.printf("%s: %s%n", author, message);
}
}

View File

@@ -0,0 +1,50 @@
package com.thalesgroup.nl.chat.impl;
import com.thalesgroup.nl.chat.api.Chat;
import org.osgi.service.component.annotations.*;
import java.util.HashMap;
import java.util.Map;
@Component(
property = {
"osgi.command.scope=chat",
"osgi.command.function=send"
},
immediate = true,
service = Object.class
)
public class ChatServer {
public static final String NAME = "Bas";
private Map<String, Chat> chatters = new HashMap<>();
@Activate
public ChatServer() {
}
@Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE)
public void addChatter(Chat chat, Map props){
String name = (String) props.get("participant.name");
System.out.printf("Adding %s%n", name);
chatters.put(name, chat);
chat.sendMessage(NAME, String.format("Hoi %s!", name));
}
public void removeChatter(Chat chat){
chatters.remove(chat);
}
public void send(String name, String message){
Chat chat = chatters.get(name);
if(chat == null){
System.out.printf("Error: %s not found%n", name);
} else {
chat.sendMessage(NAME, message);
}
}
@Deactivate
public void deactivate(){
}
}