From a30b85da6e4d3df01be929f7681ff6e202029cea Mon Sep 17 00:00:00 2001 From: Nicolas Gaud Date: Thu, 12 Mar 2020 09:51:42 +0100 Subject: [PATCH] Adding first classes of SRE network module --- .../META-INF/MANIFEST.MF | 21 +++ .../services/io.bootique.BQModuleProvider | 3 + .../OSGI-INF/l10n/bundle.properties | 3 + .../io.janusproject.network/build.properties | 10 ++ .../io.janusproject.network/pom.xml | 111 ++++++++++++ .../sarl/sre/network/boot/messages.properties | 1 + .../io/sarl/sre/network/NetworkModule.sarl | 5 + .../boot/HazelcastContextServiceModule.sarl | 1 + .../boot/HazelcastInfrastructureModule.sarl | 50 ++++++ .../io/sarl/sre/network/boot/Messages.sarl | 20 +++ .../services/HazelcastContextService.sarl | 18 ++ .../HazelcastEventTransportService.sarl | 18 ++ .../HazelcastInfrastructureService.sarl | 12 ++ .../services/HazelcastSpaceRepository.sarl | 169 ++++++++++++++++++ 14 files changed, 442 insertions(+) create mode 100644 sre/io.janusproject/io.janusproject.network/META-INF/MANIFEST.MF create mode 100644 sre/io.janusproject/io.janusproject.network/META-INF/services/io.bootique.BQModuleProvider create mode 100644 sre/io.janusproject/io.janusproject.network/OSGI-INF/l10n/bundle.properties create mode 100644 sre/io.janusproject/io.janusproject.network/build.properties create mode 100644 sre/io.janusproject/io.janusproject.network/pom.xml create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/resources/io/sarl/sre/network/boot/messages.properties create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/NetworkModule.sarl create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/HazelcastContextServiceModule.sarl create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/HazelcastInfrastructureModule.sarl create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/Messages.sarl create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastContextService.sarl create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastEventTransportService.sarl create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastInfrastructureService.sarl create mode 100644 sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastSpaceRepository.sarl diff --git a/sre/io.janusproject/io.janusproject.network/META-INF/MANIFEST.MF b/sre/io.janusproject/io.janusproject.network/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..c9cb10549b --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: io.janusproject.network;singleton:=true +Bundle-Version: 0.11.0.qualifier +Bundle-Vendor: %Bundle-Vendor +Require-Bundle: io.sarl.core;bundle-version="0.11.0", + io.sarl.util;bundle-version="0.11.0", + org.eclipse.osgi;bundle-version="3.15.100", + javax.inject;bundle-version="1.0.0", + io.bootique;bundle-version="1.0.0", + org.arakhne.afc.bootique.log4j;bundle-version="16.0.0", + org.arakhne.afc.bootique.variables;bundle-version="16.0.0", + com.google.inject;bundle-version="4.1.0", + com.hazelcast;bundle-version="4.0.0", + io.janusproject.plugin;bundle-version="0.11.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Automatic-Module-Name: io.janusproject.network +Bundle-ActivationPolicy: lazy +Export-Package: io.sarl.sre.network.boot, + io.sarl.sre.network.services diff --git a/sre/io.janusproject/io.janusproject.network/META-INF/services/io.bootique.BQModuleProvider b/sre/io.janusproject/io.janusproject.network/META-INF/services/io.bootique.BQModuleProvider new file mode 100644 index 0000000000..1656d5f425 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/META-INF/services/io.bootique.BQModuleProvider @@ -0,0 +1,3 @@ +io.sarl.sre.network.totoprovider + + diff --git a/sre/io.janusproject/io.janusproject.network/OSGI-INF/l10n/bundle.properties b/sre/io.janusproject/io.janusproject.network/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000000..a79c9d04a4 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,3 @@ +#Properties file for io.janusproject.plugin +Bundle-Vendor = janusproject.io +Bundle-Name = Janus platform diff --git a/sre/io.janusproject/io.janusproject.network/build.properties b/sre/io.janusproject/io.janusproject.network/build.properties new file mode 100644 index 0000000000..ec08c4c264 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/build.properties @@ -0,0 +1,10 @@ +source.. = src/main/sarl,\ + src/main/generated-sources/sarl +bin.includes = .,\ + META-INF/,\ + OSGI-INF/ +jre.compilation.profile = JavaSE-1.8 +#The line below is essential to enable Tycho to compile with Maven a project depending on a eclipse fragment +#You must list the corresponding fragment below +#In out case we have com.google.inject.multibindings fragments of com.google.inject +extra.. = platform:/fragment/com.google.inject.multibindings diff --git a/sre/io.janusproject/io.janusproject.network/pom.xml b/sre/io.janusproject/io.janusproject.network/pom.xml new file mode 100644 index 0000000000..491800425f --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/pom.xml @@ -0,0 +1,111 @@ + + 4.0.0 + + io.janusproject.sre + io.janusproject + 0.11.0-SNAPSHOT + + + io.janusproject + io.janusproject.network + eclipse-plugin + Janus Project Network extension + ${janusUrl} + 2020 + + + 2.${project.version} + io.sarl.sre.boot.Boot + io.sarl.sre.boot.SreMain + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + + copy-bootique-module-providers + generate-resources + + copy-resources + + + ${project.build.outputDirectory}/META-INF/services + + + ${project.basedir}/META-INF/services + false + + + true + + + + + + io.sarl.maven + sarl-maven-plugin + + + + sarl-compiler-init + initialize + + initialize + + + + sarl-compiler-compile + compile + + compile + + + + sarl-compiler-clean + clean + + clean + + + + + true + ${sarl-dsl.min.jdk.version} + ${sarl-dsl.min.jdk.version} + ${project.build.sourceEncoding} + true + true + true + true + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + src/main/sarl + + + + + org.eclipse.tycho + tycho-source-plugin + + + + + + diff --git a/sre/io.janusproject/io.janusproject.network/src/main/resources/io/sarl/sre/network/boot/messages.properties b/sre/io.janusproject/io.janusproject.network/src/main/resources/io/sarl/sre/network/boot/messages.properties new file mode 100644 index 0000000000..88cb868876 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/resources/io/sarl/sre/network/boot/messages.properties @@ -0,0 +1 @@ +HazelcastInfrastructureServiceModuleProvider_0=The configuration for the Hazelcast infrastructure module \ No newline at end of file diff --git a/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/NetworkModule.sarl b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/NetworkModule.sarl new file mode 100644 index 0000000000..1a97d6c463 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/NetworkModule.sarl @@ -0,0 +1,5 @@ +package io.sarl.sre.network + + + + diff --git a/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/HazelcastContextServiceModule.sarl b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/HazelcastContextServiceModule.sarl new file mode 100644 index 0000000000..f59e49b378 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/HazelcastContextServiceModule.sarl @@ -0,0 +1 @@ +package io.sarl.sre.network.boot diff --git a/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/HazelcastInfrastructureModule.sarl b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/HazelcastInfrastructureModule.sarl new file mode 100644 index 0000000000..e17d200258 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/HazelcastInfrastructureModule.sarl @@ -0,0 +1,50 @@ +package io.sarl.sre.network.boot + +import com.google.common.util.concurrent.Service +import com.google.inject.AbstractModule +import com.google.inject.Module +import io.bootique.BQModule +import io.bootique.BQModuleProvider +import io.sarl.sre.services.infrastructure.InfrastructureService +import javax.inject.Singleton + +import static extension com.google.inject.multibindings.Multibinder.* +import io.sarl.sre.network.services.HazelcastInfrastructureService + +/** + * Module for the Hazelcast infrastructure services. + * + * @author $Author: ngaud$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + */ +class HazelcastInfrastructureServiceModule extends AbstractModule { + + protected override configure { + typeof(InfrastructureService).bind.to(typeof(HazelcastInfrastructureService)).in(typeof(Singleton)) + + //binder.newSetBinder(typeof(Service), typeof(SreServices)).addBinding.to(typeof(InfrastructureService)) + } + +} + +/** Provider of the module for the Hazelcast infrastructure services. + * + * @author $Author: ngaud$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.9 + */ +class HazelcastInfrastructureServiceModuleProvider implements BQModuleProvider { + + override module : Module { + return new HazelcastInfrastructureServiceModule + } + + override moduleBuilder : BQModule.Builder { + return BQModule::builder(module).overrides(overrides).providerName(name).configs(configs).description(Messages::HazelcastInfrastructureServiceModuleProvider_0); + } + +} diff --git a/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/Messages.sarl b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/Messages.sarl new file mode 100644 index 0000000000..4146489c5e --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/boot/Messages.sarl @@ -0,0 +1,20 @@ +package io.sarl.sre.network.boot + +import org.eclipse.osgi.util.NLS + +final class Messages extends NLS { + + static val BUNDLE_NAME = typeof(Messages).getPackage.name + ".messages" + + static new { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, typeof(Messages)) + } + + public static var HazelcastInfrastructureServiceModuleProvider_0 : String + + + private new { + } + +} diff --git a/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastContextService.sarl b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastContextService.sarl new file mode 100644 index 0000000000..5f851fd05d --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastContextService.sarl @@ -0,0 +1,18 @@ +package io.sarl.sre.network.services + +import com.hazelcast.map.IMap +import io.sarl.lang.core.SpaceID +import io.sarl.sre.services.context.MemoryBasedContextService +import java.util.UUID + +class HazelcastContextService extends MemoryBasedContextService { + + /** + * Map linking a context id to its associated default space id. This map must be + * distributed and synchronized all over the network + */ + var defaultSpaces: IMap + + + +} diff --git a/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastEventTransportService.sarl b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastEventTransportService.sarl new file mode 100644 index 0000000000..89b87e3d0e --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastEventTransportService.sarl @@ -0,0 +1,18 @@ +package io.sarl.sre.network.services + +import io.sarl.sre.spaces.EventTransportService + +import javax.inject.Singleton +import io.sarl.lang.core.Event +import io.sarl.lang.core.EventSpace +import io.sarl.lang.core.Scope +import io.sarl.lang.core.Address + +@Singleton +class HazelcastEventTransportService implements EventTransportService { + + def routeEvent(^event : Event, ^space : EventSpace, scope : Scope) : boolean { + throw new UnsupportedOperationException("TODO: auto-generated method stub") + } + +} diff --git a/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastInfrastructureService.sarl b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastInfrastructureService.sarl new file mode 100644 index 0000000000..16d0017621 --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastInfrastructureService.sarl @@ -0,0 +1,12 @@ +package io.sarl.sre.network.services + +import io.sarl.sre.services.AbstractSreService +import io.sarl.sre.services.infrastructure.InfrastructureService +import javax.inject.Singleton + +@Singleton +class HazelcastInfrastructureService extends AbstractSreService implements InfrastructureService { + + +// +} diff --git a/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastSpaceRepository.sarl b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastSpaceRepository.sarl new file mode 100644 index 0000000000..5d0b06b2db --- /dev/null +++ b/sre/io.janusproject/io.janusproject.network/src/main/sarl/io/sarl/sre/network/services/HazelcastSpaceRepository.sarl @@ -0,0 +1,169 @@ +package io.sarl.sre.network.services + +import com.google.inject.Injector +import com.hazelcast.core.EntryEvent; +import com.hazelcast.core.EntryListener; +import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.map.IMap; +import com.hazelcast.map.MapEvent; +import io.sarl.lang.core.Space +import io.sarl.lang.core.SpaceID +import io.sarl.lang.core.SpaceSpecification +import io.sarl.sre.boot.configs.SreConfig +import io.sarl.sre.internal.SmartListenerCollection +import io.sarl.sre.services.context.LocalSpaceRepository +import io.sarl.sre.services.context.SpaceRepository.SpaceDescription +import io.sarl.sre.services.executor.ExecutorService +import java.util.ArrayList +import java.util.Iterator +import java.util.List +import java.util.Map.Entry +import java.util.UUID +import java.util.concurrent.ConcurrentHashMap +import javax.inject.Inject + +class HazelcastSpaceRepository extends LocalSpaceRepository { + + var hazelcastInstance : HazelcastInstance; + + /** + * The set of the id of all spaces stored in this repository This set must be + * distributed and synchronized all over the network. + */ + var spaceIDs : IMap + + var spaceIDsListerner : EntryListener + + @Inject + new(injector : Injector, executor : ExecutorService, config : SreConfig, + internalStructure : ConcurrentHashMap, listenerCollection : SmartListenerCollection, + iHazelcastInstance : HazelcastInstance, distributedSpaceMapName : String) { + super(injector, executor, config, listenerCollection) + hazelcastInstance = iHazelcastInstance + spaceIDs = this.hazelcastInstance.getMap(distributedSpaceMapName); + /*spaceIDsListerner = new EntryListener() { + + public override def entryAdded(^event : EntryEvent) { + assert spaceIDs.containsKey(key); + ensureLocalSpaceDefinition(key, value); + } + + public override def entryEvicted(^event : EntryEvent) { + assert !spaceIDs.containsKey(^event.getKey()); + removeLocalSpaceDefinition(^event.getKey(), false); + } + + public override def entryRemoved(^event : EntryEvent) { + assert !spaceIDs.containsKey(^event.getKey()); + removeLocalSpaceDefinition(^event.getKey(), false); + } + + public override def entryUpdated(^event : EntryEvent) { + // + } + + public override def mapCleared(^event : MapEvent) { + removeLocalSpaceDefinitions(false); + } + + public override def mapEvicted(^event : MapEvent) { + } + }*/ + + } + + protected override def createSpaceFirstInstance(spec : Class>, spaceID : SpaceID, + creationParams : Object[]) : S with S extends Space { + + this.spaceIDs.putIfAbsent(spaceID, creationParams); + + return super.createSpaceFirstInstance(spec, spaceID, creationParams); + + } + + /** + * Remove a remote space. + * + * @param id identifier of the space + * @param isLocalDestruction indicates if the destruction is initiated by the + * local kernel. + */ + /*protected def removeLocalSpaceDefinition(id : SpaceID, isLocalDestruction : boolean) { + + val ^space : Space = this.spaces.remove(id); + if (^space != null) { + this.spacesBySpec.remove(id.getSpaceSpecification(), id); + } + + if (^space != null) { + fireSpaceRemoved(^space, isLocalDestruction); + } + }*/ + + /** + * Remove all the remote spaces. + * + * @param isLocalDestruction indicates if the destruction is initiated by the + * local kernel. + */ + /*protected def removeLocalSpaceDefinitions(isLocalDestruction : boolean) { + var removedSpaces : List = null; + + if (!this.spaces.isEmpty()) { + removedSpaces = new ArrayList(this.spaces.size()); + } + + if (removedSpaces != null) { + val iterator: Iterator> = this.spaces.entrySet().iterator(); + var ^space :Space; + var id : SpaceID; + while (iterator.hasNext()) { + + var entry : Entry = iterator.next(); + id = entry.getKey(); + + ^space = entry.getValue(); + iterator.remove(); + this.spacesBySpec.remove(id.getSpaceSpecification(), id); + removedSpaces.add(^space); + } + + for (s : removedSpaces) { + fireSpaceRemoved(s, isLocalDestruction); + } + } + }*/ + + /** + * Remove all the remote spaces. + * + * @param isLocalDestruction indicates if the destruction is initiated by the + * local kernel. + */ + /*protected def removeLocalSpaceDefinitions(isLocalDestruction : boolean ) { + var removedSpaces:List = null; + + if (!this.spaces.isEmpty()) { + removedSpaces = new ArrayList<>(this.spaces.size()); + } + + if (removedSpaces != null) { + val iterator: Iterator> = this.spaces.entrySet().iterator(); + ^space : Space; + id:SpaceID ; + while (iterator.hasNext()) { + val entry: Entry = iterator.next(); + id = entry.getKey(); + ^space = entry.getValue(); + iterator.remove(); + this.spacesBySpec.remove(id.getSpaceSpecification(), id); + removedSpaces.add( ^space); + } + + for ( s : removedSpaces) { + fireSpaceRemoved(s, isLocalDestruction); + } + } + } */ + +}