-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mark Hoffmann <m.hoffmann@data-in-motion.biz>
- Loading branch information
Showing
7 changed files
with
176 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-buildpath: \ | ||
org.osgi.service.cm,\ | ||
org.osgi.util.promise |
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,16 @@ | ||
{ | ||
":configurator:resource-version": 1, | ||
|
||
"MyAlbumConfig~test1": | ||
{ | ||
"name": "Funky", | ||
"year": 1974, | ||
"album": "Funky, Funky" | ||
}, | ||
"MyAlbumConfig~test2": | ||
{ | ||
"name": "Happy", | ||
"year": 2010, | ||
"album": "I wanna be shappy" | ||
} | ||
} |
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,17 @@ | ||
-runfw: org.apache.felix.framework;version='[7.0.5,7.0.5]' | ||
-runee: JavaSE-17 | ||
-runrequires: \ | ||
bnd.identity;id='org.apache.felix.gogo.command',\ | ||
bnd.identity;id='org.apache.felix.gogo.shell',\ | ||
bnd.identity;id='org.gecko.playground.ds.config',\ | ||
bnd.identity;id='org.apache.felix.configadmin' | ||
-runbundles: \ | ||
org.apache.felix.configadmin;version='[1.9.26,1.9.27)',\ | ||
org.apache.felix.gogo.command;version='[1.1.2,1.1.3)',\ | ||
org.apache.felix.gogo.runtime;version='[1.1.6,1.1.7)',\ | ||
org.apache.felix.gogo.shell;version='[1.1.4,1.1.5)',\ | ||
org.apache.felix.scr;version='[2.2.6,2.2.7)',\ | ||
org.gecko.playground.ds.config;version=snapshot,\ | ||
org.osgi.service.component;version='[1.5.1,1.5.2)',\ | ||
org.osgi.util.function;version='[1.2.0,1.2.1)',\ | ||
org.osgi.util.promise;version='[1.3.0,1.3.1)' |
40 changes: 40 additions & 0 deletions
40
org.gecko.playground.ds.config/src/org/gecko/playground/ds/config/AlbumComponent.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,40 @@ | ||
/** | ||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||
* All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Data In Motion - initial API and implementation | ||
*/ | ||
package org.gecko.playground.ds.config; | ||
|
||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.ConfigurationPolicy; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
import org.osgi.service.component.annotations.Modified; | ||
|
||
@Component(name = "MyAlbumConfig", configurationPolicy = ConfigurationPolicy.REQUIRE) | ||
public class AlbumComponent { | ||
|
||
@Activate | ||
public void activate(MyFancyConfig c) { | ||
System.out.println("Activate " + c.name() + " from " + c.year() + "(" + c.album() + ") from instance " + this); | ||
} | ||
|
||
@Modified | ||
public void modified(MyFancyConfig c) { | ||
System.out.println("Modified " + c.name() + " from " + c.year() + "(" + c.album() + ") from instance " + this); | ||
|
||
} | ||
|
||
@Deactivate | ||
public void deactivate(MyFancyConfig c) { | ||
System.out.println("De-Activate " + c.name() + " from " + c.year() + "(" + c.album() + ") from instance " + this); | ||
|
||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
org.gecko.playground.ds.config/src/org/gecko/playground/ds/config/AlbumCreator.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,79 @@ | ||
package org.gecko.playground.ds.config; | ||
|
||
import java.io.IOException; | ||
import java.util.Dictionary; | ||
import java.util.Hashtable; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.concurrent.Executors; | ||
|
||
import org.osgi.service.cm.Configuration; | ||
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.Reference; | ||
import org.osgi.util.promise.PromiseFactory; | ||
|
||
@Component | ||
public class AlbumCreator { | ||
|
||
@Reference | ||
private ConfigurationAdmin configAdmin; | ||
private List<Configuration> configs = new LinkedList<>(); | ||
|
||
@Activate | ||
public void activate() { | ||
PromiseFactory pf = new PromiseFactory(Executors.newSingleThreadExecutor()); | ||
pf.submit(this::createConfigs); | ||
} | ||
|
||
private Void createConfigs() { | ||
for (int i = 0; i < 10; i++) { | ||
createConfiguration(i, 0); | ||
try { | ||
Thread.sleep(1000l); | ||
} catch (InterruptedException e) { | ||
} | ||
} | ||
try { | ||
Thread.sleep(2000l); | ||
} catch (InterruptedException e) { | ||
} | ||
for (int i = 0; i < 10; i++) { | ||
createConfiguration(i, 5); | ||
try { | ||
Thread.sleep(1000l); | ||
} catch (InterruptedException e) { | ||
} | ||
} | ||
try { | ||
Thread.sleep(2000l); | ||
} catch (InterruptedException e) { | ||
} | ||
configs.forEach(c->{ | ||
try { | ||
c.delete(); | ||
} catch (Exception e) { | ||
// TODO: handle exception | ||
} | ||
}); | ||
configs.clear(); | ||
return null; | ||
} | ||
|
||
private void createConfiguration(int increment, int offset) { | ||
Configuration configuration; | ||
try { | ||
configuration = configAdmin.getFactoryConfiguration("MyAlbumConfig", "album-" + increment, "?"); | ||
Dictionary<String, Object> props = new Hashtable<>(); | ||
props.put("name", "name-" + increment); | ||
props.put("album", "album-" + increment + offset); | ||
props.put("year", 2000 + increment + offset); | ||
configuration.updateIfDifferent(props); | ||
configs.add(configuration); | ||
} catch (IOException e) { | ||
System.out.println("Error creating configuration: " + e.getMessage()); | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
org.gecko.playground.ds.config/src/org/gecko/playground/ds/config/MyFancyConfig.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,20 @@ | ||
/** | ||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||
* All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Data In Motion - initial API and implementation | ||
*/ | ||
package org.gecko.playground.ds.config; | ||
|
||
public @interface MyFancyConfig { | ||
|
||
String name(); | ||
int year() default 42; | ||
String album() default "nothing to say"; | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
org.gecko.playground.ds.config/src/org/gecko/playground/ds/config/package-info.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 @@ | ||
package org.gecko.playground.ds.config; |