1 package org
.argeo
.cms
.runtime
;
3 import java
.nio
.file
.Path
;
4 import java
.nio
.file
.Paths
;
5 import java
.util
.concurrent
.CompletableFuture
;
7 import org
.argeo
.api
.acr
.ContentRepository
;
8 import org
.argeo
.api
.acr
.spi
.ProvidedRepository
;
9 import org
.argeo
.api
.cms
.CmsContext
;
10 import org
.argeo
.api
.cms
.CmsDeployment
;
11 import org
.argeo
.api
.cms
.CmsState
;
12 import org
.argeo
.api
.cms
.directory
.CmsUserManager
;
13 import org
.argeo
.api
.cms
.transaction
.SimpleTransactionManager
;
14 import org
.argeo
.api
.cms
.transaction
.WorkControl
;
15 import org
.argeo
.api
.cms
.transaction
.WorkTransaction
;
16 import org
.argeo
.api
.register
.Component
;
17 import org
.argeo
.api
.register
.ComponentRegister
;
18 import org
.argeo
.api
.register
.SimpleRegister
;
19 import org
.argeo
.api
.uuid
.ConcurrentUuidFactory
;
20 import org
.argeo
.api
.uuid
.NodeIdSupplier
;
21 import org
.argeo
.api
.uuid
.UuidFactory
;
22 import org
.argeo
.cms
.internal
.runtime
.CmsContextImpl
;
23 import org
.argeo
.cms
.internal
.runtime
.CmsDeploymentImpl
;
24 import org
.argeo
.cms
.internal
.runtime
.CmsStateImpl
;
25 import org
.argeo
.cms
.internal
.runtime
.CmsUserAdmin
;
26 import org
.argeo
.cms
.internal
.runtime
.CmsUserManagerImpl
;
27 import org
.argeo
.cms
.internal
.runtime
.DeployedContentRepository
;
28 import org
.osgi
.service
.useradmin
.UserAdmin
;
31 * A CMS assembly which is programmatically defined, as an alternative to OSGi
32 * deployment. Useful for testing or AOT compilation.
34 public class StaticCms
{
35 private SimpleRegister register
= new SimpleRegister();
37 private CompletableFuture
<Void
> stopped
= new CompletableFuture
<Void
>();
41 CmsStateImpl cmsState
= new CmsStateImpl();
42 Component
<CmsStateImpl
> cmsStateC
= new Component
.Builder
<>(cmsState
) //
43 .addType(CmsState
.class) //
44 .addType(NodeIdSupplier
.class) //
45 .addActivation(cmsState
::start
) //
46 .addDeactivation(cmsState
::stop
) //
50 ConcurrentUuidFactory uuidFactory
= new ConcurrentUuidFactory();
51 Component
<ConcurrentUuidFactory
> uuidFactoryC
= new Component
.Builder
<>(uuidFactory
) //
52 .addType(UuidFactory
.class) //
53 .addDependency(cmsStateC
.getType(NodeIdSupplier
.class), uuidFactory
::setNodeIdSupplier
, null) //
56 // Transaction manager
57 SimpleTransactionManager transactionManager
= new SimpleTransactionManager();
58 Component
<SimpleTransactionManager
> transactionManagerC
= new Component
.Builder
<>(transactionManager
) //
59 .addType(WorkControl
.class) //
60 .addType(WorkTransaction
.class) //
64 CmsUserAdmin userAdmin
= new CmsUserAdmin();
65 Component
<CmsUserAdmin
> userAdminC
= new Component
.Builder
<>(userAdmin
) //
66 .addType(UserAdmin
.class) //
67 .addActivation(userAdmin
::start
) //
68 .addDeactivation(userAdmin
::stop
) //
69 .addDependency(cmsStateC
.getType(CmsState
.class), userAdmin
::setCmsState
, null) //
70 .addDependency(transactionManagerC
.getType(WorkControl
.class), userAdmin
::setTransactionManager
, null) //
71 .addDependency(transactionManagerC
.getType(WorkTransaction
.class), userAdmin
::setUserTransaction
, null) //
75 CmsUserManagerImpl userManager
= new CmsUserManagerImpl();
76 // for (UserDirectory userDirectory : userAdmin.getUserDirectories()) {
77 // // FIXME deal with properties
78 // userManager.addUserDirectory(userDirectory, new HashMap<>());
80 Component
<CmsUserManagerImpl
> userManagerC
= new Component
.Builder
<>(userManager
) //
81 .addType(CmsUserManager
.class) //
82 .addActivation(userManager
::start
) //
83 .addDeactivation(userManager
::stop
) //
84 .addDependency(userAdminC
.getType(UserAdmin
.class), userManager
::setUserAdmin
, null) //
85 .addDependency(transactionManagerC
.getType(WorkTransaction
.class), userManager
::setUserTransaction
,
90 DeployedContentRepository contentRepository
= new DeployedContentRepository();
91 Component
<DeployedContentRepository
> contentRepositoryC
= new Component
.Builder
<>(contentRepository
) //
92 .addType(ProvidedRepository
.class) //
93 .addType(ContentRepository
.class) //
94 .addActivation(contentRepository
::start
) //
95 .addDeactivation(contentRepository
::stop
) //
96 .addDependency(cmsStateC
.getType(CmsState
.class), contentRepository
::setCmsState
, null) //
97 .addDependency(uuidFactoryC
.getType(UuidFactory
.class), contentRepository
::setUuidFactory
, null) //
98 .addDependency(userManagerC
.getType(CmsUserManager
.class), contentRepository
::setUserManager
, null) //
102 CmsDeploymentImpl cmsDeployment
= new CmsDeploymentImpl();
103 Component
<CmsDeploymentImpl
> cmsDeploymentC
= new Component
.Builder
<>(cmsDeployment
) //
104 .addType(CmsDeployment
.class) //
105 .addActivation(cmsDeployment
::start
) //
106 .addDeactivation(cmsDeployment
::stop
) //
107 .addDependency(cmsStateC
.getType(CmsState
.class), cmsDeployment
::setCmsState
, null) //
108 // .addDependency(deployConfigC.getType(DeployConfig.class), cmsDeployment::setDeployConfig, null) //
112 CmsContextImpl cmsContext
= new CmsContextImpl();
113 Component
<CmsContextImpl
> cmsContextC
= new Component
.Builder
<>(cmsContext
) //
114 .addType(CmsContext
.class) //
115 .addActivation(cmsContext
::start
) //
116 .addDeactivation(cmsContext
::stop
) //
117 .addDependency(cmsStateC
.getType(CmsState
.class), cmsContext
::setCmsState
, null) //
118 .addDependency(cmsDeploymentC
.getType(CmsDeployment
.class), cmsContext
::setCmsDeployment
, null) //
119 .addDependency(userAdminC
.getType(UserAdmin
.class), cmsContext
::setUserAdmin
, null) //
120 .addDependency(uuidFactoryC
.getType(UuidFactory
.class), cmsContext
::setUuidFactory
, null) //
121 // .addDependency(contentRepositoryC.getType(ProvidedRepository.class), cmsContext::setContentRepository,
124 assert cmsContextC
.get() == cmsContext
;
126 addComponents(register
);
130 postActivation(register
);
133 protected void addComponents(ComponentRegister register
) {
137 protected void postActivation(ComponentRegister register
) {
141 public ComponentRegister
getComponentRegister() {
146 if (register
.isActive()) {
147 register
.deactivate();
150 stopped
.complete(null);
153 public void waitForStop() {
157 public static void main(String
[] args
) {
158 if (args
.length
== 0) {
159 System
.err
.println("Usage: <data path>");
162 Path instancePath
= Paths
.get(args
[0]);
163 System
.setProperty("osgi.instance.area", instancePath
.toUri().toString());
165 StaticCms staticCms
= new StaticCms();
166 Runtime
.getRuntime().addShutdownHook(new Thread(() -> staticCms
.stop(), "Static CMS Shutdown"));
168 staticCms
.waitForStop();