ENTAXY-248 release 1.8.1
This commit is contained in:
201
platform/runtime/core/cluster/LICENSE.txt
Normal file
201
platform/runtime/core/cluster/LICENSE.txt
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
@ -0,0 +1,113 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>cluster</artifactId>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core.cluster</groupId>
|
||||
<artifactId>cluster-persistence-service</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>ENTAXY :: PLATFORM :: CORE :: CLUSTER :: PERSISTENCE</name>
|
||||
<description>ENTAXY :: PLATFORM :: CORE :: CLUSTER :: PERSISTENCE</description>
|
||||
|
||||
<properties>
|
||||
<bundle.osgi.private.pkg>
|
||||
ru.entaxy.esb.platform.core.cluster.persistence.activator,
|
||||
ru.entaxy.esb.platform.core.cluster.persistence.handler
|
||||
</bundle.osgi.private.pkg>
|
||||
<bundle.osgi.import.pkg>
|
||||
!org.apache.karaf.cellar.bundle.shell*,
|
||||
org.osgi.framework,
|
||||
*
|
||||
</bundle.osgi.import.pkg>
|
||||
<bundle.osgi.export.pkg>
|
||||
ru.entaxy.esb.platform.core.cluster.persistence
|
||||
</bundle.osgi.export.pkg>
|
||||
<bundle.osgi.dynamicimport.pkg>
|
||||
*
|
||||
</bundle.osgi.dynamicimport.pkg>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.karaf.features</groupId>
|
||||
<artifactId>org.apache.karaf.features.core</artifactId>
|
||||
<version>${karaf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>osgi.core</artifactId>
|
||||
<version>${osgi.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.karaf</groupId>
|
||||
<artifactId>org.apache.karaf.util</artifactId>
|
||||
<version>${karaf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.compendium</artifactId>
|
||||
<version>${osgi.compendium.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hazelcast</groupId>
|
||||
<artifactId>hazelcast-all</artifactId>
|
||||
<version>${hazelcast.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.karaf.cellar</groupId>
|
||||
<artifactId>org.apache.karaf.cellar.core</artifactId>
|
||||
<version>${cellar.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.karaf</groupId>
|
||||
<artifactId>org.apache.karaf.util</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.karaf.cellar</groupId>
|
||||
<artifactId>org.apache.karaf.cellar.bundle</artifactId>
|
||||
<version>${cellar.version}-ENTAXY</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.karaf</groupId>
|
||||
<artifactId>org.apache.karaf.util</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.karaf.cellar</groupId>
|
||||
<artifactId>org.apache.karaf.cellar.hazelcast</artifactId>
|
||||
<version>${cellar.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.karaf.tooling</groupId>
|
||||
<artifactId>karaf-services-maven-plugin</artifactId>
|
||||
<version>${karaf.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>service-metadata-generate</id>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>service-metadata-generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactInclude>.*</artifactInclude>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,146 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.karaf.cellar.bundle.BundleState;
|
||||
import org.apache.karaf.cellar.core.ClusterManager;
|
||||
import org.apache.karaf.cellar.core.Configurations;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Helper<T> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Helper.class);
|
||||
|
||||
public static final String DELIMITER = "~~_DEL_~~";
|
||||
public static final String SEPARATOR = "~~_SEP_~~";
|
||||
|
||||
protected String mapBaseName;
|
||||
protected String classifier;
|
||||
protected Class<T> dataClass;
|
||||
|
||||
protected Serializer<T> serializer;
|
||||
|
||||
protected String rootPath;
|
||||
protected String subPath;
|
||||
|
||||
protected ServiceProvider serviceProvider;
|
||||
|
||||
public Helper(ServiceProvider serviceProvider, String mapBaseName, String classifier, Class<T> dataClass) {
|
||||
this.serviceProvider = serviceProvider;
|
||||
this.mapBaseName = mapBaseName;
|
||||
this.classifier = classifier;
|
||||
this.dataClass = dataClass;
|
||||
this.serializer = new Serializer<>(this.dataClass);
|
||||
this.rootPath = System.getProperty("karaf.home");
|
||||
this.subPath = "cluster-state";
|
||||
}
|
||||
|
||||
protected Path getTargetPath(String groupName) {
|
||||
String fileName = "cluster." + classifier + "." + groupName + ".state";
|
||||
Path p = Paths.get(this.rootPath, this.subPath, fileName);
|
||||
return p;
|
||||
}
|
||||
|
||||
public void saveClusterState(String groupName) {
|
||||
|
||||
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(this.dataClass.getClassLoader());
|
||||
|
||||
if (!checkGroup(groupName))
|
||||
return;
|
||||
|
||||
ClusterManager clusterManager = this.serviceProvider.getClusterManager();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, T> clusterData = clusterManager.getMap(this.mapBaseName + Configurations.SEPARATOR + groupName);
|
||||
String serialized = "";
|
||||
serialized = clusterData.entrySet().stream()
|
||||
.<String>map((entry)->{return entry.getKey() + DELIMITER + serializer.toString(entry.getValue());})
|
||||
.collect(Collectors.joining(SEPARATOR));
|
||||
Path p = getTargetPath(groupName);
|
||||
try {
|
||||
// if (!p.toFile().exists())
|
||||
// p.toFile().createNewFile();
|
||||
Files.createDirectories(p.getParent());
|
||||
Files.write(p, serialized.getBytes());
|
||||
} catch (IOException e) {
|
||||
log.error("FAILED saving state to [" + p.toUri().toString() + "]", e);
|
||||
}
|
||||
|
||||
Thread.currentThread().setContextClassLoader(originalClassLoader);
|
||||
|
||||
}
|
||||
|
||||
public void loadClusterState(String groupName) {
|
||||
|
||||
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(this.dataClass.getClassLoader());
|
||||
|
||||
if (!checkGroup(groupName))
|
||||
return;
|
||||
|
||||
Path p = getTargetPath(groupName);
|
||||
if (!p.toFile().exists()) {
|
||||
log.info("File [{}] doesn't exist, skip loading [{}] from [{}]"
|
||||
, p.toUri().toString()
|
||||
, this.classifier
|
||||
, this.mapBaseName);
|
||||
return;
|
||||
}
|
||||
|
||||
String data = "";
|
||||
try {
|
||||
data = Files.readString(p);
|
||||
} catch (IOException e) {
|
||||
log.error("Error reading data from [" + p.toUri().toString() + "]", e);
|
||||
}
|
||||
if ((data == null) || data.length()==0 )
|
||||
return;
|
||||
|
||||
ClusterManager clusterManager = this.serviceProvider.getClusterManager();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, T> clusterData = clusterManager.getMap(this.mapBaseName + Configurations.SEPARATOR + groupName);
|
||||
|
||||
String[] entries = data.split(SEPARATOR);
|
||||
for (int i=0; i<entries.length; i++) {
|
||||
String[] entry = entries[i].split(DELIMITER);
|
||||
T object = serializer.fromString(entry[1]);
|
||||
clusterData.put(entry[0], object);
|
||||
}
|
||||
|
||||
Thread.currentThread().setContextClassLoader(originalClassLoader);
|
||||
|
||||
}
|
||||
|
||||
protected boolean checkGroup(String groupName) {
|
||||
// TODO implement check
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PersistenceManager<T> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PersistenceManager.class);
|
||||
|
||||
private static class UpdateMarker {
|
||||
|
||||
private boolean updated = false;
|
||||
|
||||
public void update() {
|
||||
this.updated = true;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.updated = false;
|
||||
}
|
||||
|
||||
public boolean isUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static interface UpdateTaskCallback {
|
||||
public void executed();
|
||||
}
|
||||
|
||||
private class Executor implements UpdateTaskCallback {
|
||||
|
||||
private Boolean isRunning = false;
|
||||
|
||||
private ExecutorService threadPool = Executors.newSingleThreadExecutor();
|
||||
|
||||
public synchronized void run() {
|
||||
synchronized (isRunning) {
|
||||
if (this.isRunning)
|
||||
return;
|
||||
this.isRunning = true;
|
||||
log.info("~~> EXECUTOR :: RUN");
|
||||
UpdateTask ut = new UpdateTask(PersistenceManager.this.helper, this);
|
||||
PersistenceManager.this.clear();
|
||||
threadPool.execute(ut);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void executed() {
|
||||
log.info("~~> EXECUTOR :: EXECUTED");
|
||||
synchronized (isRunning) {
|
||||
this.isRunning = false;
|
||||
}
|
||||
PersistenceManager.this.executed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class UpdateTask implements Runnable {
|
||||
|
||||
private Helper<?> helper;
|
||||
private UpdateTaskCallback callback;
|
||||
|
||||
public UpdateTask(Helper<?> helper, UpdateTaskCallback callback) {
|
||||
this.helper = helper;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
log.debug("~~> UPDATE_TASK :: RUN");
|
||||
try {
|
||||
log.debug("~~> UPDATE_TASK :: RUN :: sleeping");
|
||||
Thread.currentThread().sleep(15000);
|
||||
log.debug("~~> UPDATE_TASK :: RUN :: processig");
|
||||
// TODO add support for different groups
|
||||
this.helper.saveClusterState("default");
|
||||
log.debug("~~> UPDATE_TASK :: RUN :: processed");
|
||||
this.callback.executed();
|
||||
} catch (InterruptedException e) {
|
||||
log.error("UpdateTask", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final UpdateMarker marker = new UpdateMarker();
|
||||
|
||||
private Helper<T> helper;
|
||||
|
||||
private Executor executor = new Executor();
|
||||
|
||||
public PersistenceManager(ServiceProvider serviceProvider, String mapBaseName, String classifier, Class<T> dataClass) {
|
||||
|
||||
helper = new Helper<>(serviceProvider, mapBaseName, classifier, dataClass);
|
||||
|
||||
}
|
||||
|
||||
public void restore() {
|
||||
// this is called only once before the consumer started
|
||||
// so we can call helper directly
|
||||
helper.loadClusterState("default");
|
||||
}
|
||||
|
||||
public void persist() {
|
||||
this.updated();
|
||||
}
|
||||
|
||||
protected void runExecutor() {
|
||||
synchronized (executor) {
|
||||
if (!executor.isRunning)
|
||||
executor.run();
|
||||
}
|
||||
}
|
||||
|
||||
public void updated() {
|
||||
log.info("~~> UPDATED");
|
||||
synchronized (marker) {
|
||||
marker.update();
|
||||
}
|
||||
runExecutor();
|
||||
}
|
||||
|
||||
protected synchronized void clear() {
|
||||
synchronized (marker) {
|
||||
marker.clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized void executed() {
|
||||
boolean updated = false;
|
||||
synchronized (marker) {
|
||||
updated = marker.isUpdated();
|
||||
}
|
||||
if (updated)
|
||||
runExecutor();
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Serializer<T> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Serializer.class);
|
||||
|
||||
|
||||
private Class<T> dataClass;
|
||||
|
||||
public Serializer(Class<T> clazz) {
|
||||
this.dataClass = clazz;
|
||||
}
|
||||
|
||||
public String toString(T object) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos;
|
||||
try {
|
||||
oos = new ObjectOutputStream( baos );
|
||||
oos.writeObject((Serializable) object);
|
||||
oos.close();
|
||||
} catch (IOException e) {
|
||||
log.error("Serializer.toString", e);
|
||||
}
|
||||
return Base64.getEncoder().encodeToString(baos.toByteArray());
|
||||
}
|
||||
|
||||
public T fromString(String str) {
|
||||
byte [] data = Base64.getDecoder().decode(str);
|
||||
// ClassLoader original = Thread.currentThread().getContextClassLoader();
|
||||
// Thread.currentThread().setContextClassLoader(dataClass.getClassLoader());
|
||||
T result = null;
|
||||
try {
|
||||
ObjectInputStream ois = new ObjectInputStream(
|
||||
new ByteArrayInputStream( data ) );
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
result = dataClass.cast(o);
|
||||
} catch (Exception e) {
|
||||
result = null;
|
||||
}
|
||||
// Thread.currentThread().setContextClassLoader(original);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence;
|
||||
|
||||
import org.apache.karaf.cellar.core.ClusterManager;
|
||||
import org.apache.karaf.cellar.core.GroupManager;
|
||||
|
||||
public interface ServiceProvider {
|
||||
|
||||
public ClusterManager getClusterManager();
|
||||
public GroupManager getGroupManager();
|
||||
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* hazelcast-test
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence.activator;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.karaf.cellar.bundle.BundleState;
|
||||
import org.apache.karaf.cellar.bundle.Constants;
|
||||
import org.apache.karaf.cellar.bundle.management.CellarBundleMBean;
|
||||
import org.apache.karaf.cellar.core.ClusterManager;
|
||||
import org.apache.karaf.cellar.core.GroupManager;
|
||||
import org.apache.karaf.cellar.core.event.EventHandler;
|
||||
import org.apache.karaf.features.FeaturesService;
|
||||
import org.apache.karaf.util.tracker.BaseActivator;
|
||||
import org.apache.karaf.util.tracker.annotation.ProvideService;
|
||||
import org.apache.karaf.util.tracker.annotation.RequireService;
|
||||
import org.apache.karaf.util.tracker.annotation.Services;
|
||||
import org.osgi.service.cm.ConfigurationAdmin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.Member;
|
||||
import com.hazelcast.core.MemberAttributeEvent;
|
||||
import com.hazelcast.core.MembershipEvent;
|
||||
import com.hazelcast.core.MembershipListener;
|
||||
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.PersistenceManager;
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.ServiceProvider;
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.handler.LocalBundleEventHandler;
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.handler.LocalEventHandlerRegistryDispatcher;
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.handler.LocalHandlerRegistry;
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.handler.LocalTopicConsumer;
|
||||
|
||||
@Services(requires = {
|
||||
@RequireService(ClusterManager.class),
|
||||
@RequireService(GroupManager.class),
|
||||
@RequireService(CellarBundleMBean.class),
|
||||
@RequireService(ConfigurationAdmin.class),
|
||||
@RequireService(FeaturesService.class),
|
||||
@RequireService(HazelcastInstance.class)
|
||||
},
|
||||
provides = {
|
||||
@ProvideService(EventHandler.class)
|
||||
}
|
||||
)
|
||||
public class Activator extends BaseActivator implements ServiceProvider, MembershipListener {
|
||||
|
||||
private static final String CLASSIFIER_BUNDLE = "bundle";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BaseActivator.class);
|
||||
|
||||
private LocalBundleEventHandler bundleEventHandler;
|
||||
|
||||
private LocalTopicConsumer consumer;
|
||||
|
||||
private LocalEventHandlerRegistryDispatcher dispatcher;
|
||||
|
||||
private LocalHandlerRegistry handlerRegistry;
|
||||
|
||||
private ClusterManager clusterManager;
|
||||
|
||||
private GroupManager groupManager;
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
private Map<String, PersistenceManager> managers = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception {
|
||||
clusterManager = getTrackedService(ClusterManager.class);
|
||||
if (clusterManager == null)
|
||||
return;
|
||||
groupManager = getTrackedService(GroupManager.class);
|
||||
if (groupManager == null)
|
||||
return;
|
||||
ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
|
||||
if (configurationAdmin == null)
|
||||
return;
|
||||
FeaturesService featuresService = getTrackedService(FeaturesService.class);
|
||||
if (featuresService == null)
|
||||
return;
|
||||
|
||||
hazelcastInstance = getTrackedService(HazelcastInstance.class);
|
||||
if (hazelcastInstance == null)
|
||||
return;
|
||||
|
||||
handlerRegistry = new LocalHandlerRegistry<>();
|
||||
|
||||
/*
|
||||
* bundle management
|
||||
*/
|
||||
|
||||
PersistenceManager<BundleState> bundlePersistenceManager = new PersistenceManager<>(this
|
||||
, Constants.BUNDLE_MAP
|
||||
, CLASSIFIER_BUNDLE
|
||||
, BundleState.class);
|
||||
this.managers.put(CLASSIFIER_BUNDLE, bundlePersistenceManager);
|
||||
|
||||
bundleEventHandler = new LocalBundleEventHandler();
|
||||
bundleEventHandler.setConfigurationAdmin(configurationAdmin);
|
||||
bundleEventHandler.setClusterManager(clusterManager);
|
||||
bundleEventHandler.setGroupManager(groupManager);
|
||||
bundleEventHandler.setBundleContext(bundleContext);
|
||||
bundleEventHandler.setFeaturesService(featuresService);
|
||||
bundleEventHandler.setPersistenceManager(bundlePersistenceManager);
|
||||
bundleEventHandler.init();
|
||||
handlerRegistry.addHandler(bundleEventHandler);
|
||||
|
||||
/*
|
||||
* feature management
|
||||
*/
|
||||
// TODO
|
||||
|
||||
/*
|
||||
* kar management
|
||||
*/
|
||||
// TODO
|
||||
|
||||
|
||||
/*
|
||||
* common services
|
||||
*/
|
||||
|
||||
dispatcher = new LocalEventHandlerRegistryDispatcher<>();
|
||||
dispatcher.setHandlerRegistry(handlerRegistry);
|
||||
dispatcher.init();
|
||||
|
||||
consumer = new LocalTopicConsumer();
|
||||
consumer.setInstance(hazelcastInstance);
|
||||
consumer.setDispatcher(dispatcher);
|
||||
consumer.setNode(clusterManager.getNode());
|
||||
consumer.setConfigurationAdmin(configurationAdmin);
|
||||
consumer.init();
|
||||
|
||||
|
||||
if (iAmAlone()) {
|
||||
restoreAll();
|
||||
consumer.start();
|
||||
}
|
||||
hazelcastInstance.getCluster().addMembershipListener(this);
|
||||
|
||||
}
|
||||
|
||||
protected void checkStartStopConsumer() {
|
||||
if (iAmAlone())
|
||||
consumer.start();
|
||||
else
|
||||
consumer.stop();
|
||||
}
|
||||
|
||||
protected void restoreAll() {
|
||||
for (PersistenceManager pm: managers.values())
|
||||
pm.restore();
|
||||
}
|
||||
|
||||
protected void persistAll() {
|
||||
for (PersistenceManager pm: managers.values())
|
||||
pm.persist();
|
||||
}
|
||||
|
||||
protected boolean iAmAlone() {
|
||||
if (hazelcastInstance.getCluster().getMembers().size()>1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() {
|
||||
// TODO Auto-generated method stub
|
||||
super.doStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterManager getClusterManager() {
|
||||
return clusterManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupManager getGroupManager() {
|
||||
return groupManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberAdded(MembershipEvent membershipEvent) {
|
||||
Member member = membershipEvent.getMember();
|
||||
Member local = hazelcastInstance.getCluster().getLocalMember();
|
||||
checkStartStopConsumer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberAttributeChanged(MemberAttributeEvent event) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberRemoved(MembershipEvent membershipEvent) {
|
||||
Member member = membershipEvent.getMember();
|
||||
Member local = hazelcastInstance.getCluster().getLocalMember();
|
||||
if (member.equals(local))
|
||||
consumer.stop();
|
||||
else if (iAmAlone()) {
|
||||
// all other nodes gone
|
||||
persistAll();
|
||||
consumer.start();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
/*
|
||||
* 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 ru.entaxy.esb.platform.core.cluster.persistence.handler;
|
||||
|
||||
import org.apache.karaf.cellar.bundle.BundleEventHandler;
|
||||
import org.apache.karaf.cellar.bundle.BundleState;
|
||||
import org.apache.karaf.cellar.bundle.BundleSupport;
|
||||
import org.apache.karaf.cellar.bundle.ClusterBundleEvent;
|
||||
import org.apache.karaf.cellar.bundle.Constants;
|
||||
import org.apache.karaf.cellar.core.Configurations;
|
||||
import org.apache.karaf.cellar.core.control.BasicSwitch;
|
||||
import org.apache.karaf.cellar.core.control.Switch;
|
||||
import org.apache.karaf.cellar.core.control.SwitchStatus;
|
||||
import org.apache.karaf.cellar.core.event.EventHandler;
|
||||
import org.apache.karaf.cellar.core.event.EventType;
|
||||
import org.apache.karaf.features.Feature;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleException;
|
||||
import org.osgi.framework.wiring.FrameworkWiring;
|
||||
import org.osgi.service.cm.Configuration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.PersistenceManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The BundleEventHandler is responsible to process received cluster event for bundles.
|
||||
*/
|
||||
public class LocalBundleEventHandler extends BundleSupport implements EventHandler<ClusterBundleEvent> {
|
||||
|
||||
private static final transient Logger log = LoggerFactory.getLogger(LocalBundleEventHandler.class);
|
||||
|
||||
public static final String SWITCH_ID = "org.apache.karaf.cellar.bundle.handler";
|
||||
|
||||
private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
|
||||
|
||||
private PersistenceManager persistenceManager;
|
||||
|
||||
/**
|
||||
* Handle received bundle cluster events.
|
||||
*
|
||||
* @param event the received bundle cluster event.
|
||||
*/
|
||||
@Override
|
||||
public void handle(ClusterBundleEvent event) {
|
||||
|
||||
// check if the handler switch is ON
|
||||
if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
|
||||
log.debug("CELLAR BUNDLE: {} switch is OFF, cluster event is not handled", SWITCH_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (groupManager == null) {
|
||||
//in rare cases for example right after installation this happens!
|
||||
log.error("CELLAR BUNDLE: retrieved event {} while groupManager is not available yet!", event);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if the group is local
|
||||
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
|
||||
log.debug("CELLAR BUNDLE: node is not part of the event cluster group {}", event.getSourceGroup().getName());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// check if it's not a "local" event
|
||||
if (event.getLocal() != null && event.getLocal().getId().equalsIgnoreCase(clusterManager.getNode().getId())) {
|
||||
log.trace("CELLAR BUNDLE: cluster event is local (coming from local synchronizer or listener)");
|
||||
return;
|
||||
}
|
||||
// check if the pid is marked as local.
|
||||
if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, event.getLocation(), EventType.INBOUND)) {
|
||||
// check the features first
|
||||
List<Feature> matchingFeatures = retrieveFeature(event.getLocation());
|
||||
for (Feature feature : matchingFeatures) {
|
||||
if (!isAllowed(event.getSourceGroup(), "feature", feature.getName(), EventType.INBOUND)) {
|
||||
log.trace("CELLAR BUNDLE: bundle {} is contained in feature {} marked BLOCKED INBOUND for cluster group {}", event.getLocation(), feature.getName(), event.getSourceGroup().getName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO mark cluster state as needed to be saved
|
||||
log.info("-->> WE NEED TO SAVE CLUSTER STATE");
|
||||
this.persistenceManager.updated();
|
||||
|
||||
} else
|
||||
log.trace("CELLAR BUNDLE: bundle {} is marked BLOCKED INBOUND for cluster group {}", event.getSymbolicName(), event.getSourceGroup().getName());
|
||||
} catch (BundleException e) {
|
||||
log.error("CELLAR BUNDLE: failed to install bundle {}/{}.", new Object[]{event.getSymbolicName(), event.getVersion()}, e);
|
||||
} catch (Exception e) {
|
||||
log.error("CELLAR BUNDLE: failed to handle bundle event", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster bundle event handler switch.
|
||||
*
|
||||
* @return the cluster bundle event handler switch.
|
||||
*/
|
||||
@Override
|
||||
public Switch getSwitch() {
|
||||
// load the switch status from the config
|
||||
try {
|
||||
Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null);
|
||||
if (configuration != null) {
|
||||
Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.HANDLER
|
||||
+ "."
|
||||
+ BundleEventHandler.class.getName()));
|
||||
if (status) {
|
||||
eventSwitch.turnOn();
|
||||
} else {
|
||||
eventSwitch.turnOff();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return eventSwitch;
|
||||
}
|
||||
|
||||
public void setPersistenceManager(PersistenceManager persistenceManager) {
|
||||
this.persistenceManager = persistenceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster event type.
|
||||
*
|
||||
* @return the cluster bundle event type.
|
||||
*/
|
||||
@Override
|
||||
public Class<ClusterBundleEvent> getType() {
|
||||
return ClusterBundleEvent.class;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
/*
|
||||
* 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 ru.entaxy.esb.platform.core.cluster.persistence.handler;
|
||||
|
||||
import org.apache.karaf.cellar.core.event.Event;
|
||||
import org.apache.karaf.cellar.core.event.EventHandler;
|
||||
import org.apache.karaf.cellar.core.event.EventHandlerRegistry;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Event dispatcher task.
|
||||
*/
|
||||
public class LocalEventDispatchTask<E extends Event> implements Runnable {
|
||||
|
||||
private static final transient Logger LOGGER = LoggerFactory.getLogger(LocalEventDispatchTask.class);
|
||||
private static final long DEFAULT_TIMEOUT = 30000;
|
||||
|
||||
private E event;
|
||||
private EventHandlerRegistry handlerRegistry;
|
||||
private long timeout;
|
||||
private long interval = 1000;
|
||||
|
||||
public LocalEventDispatchTask(E event, EventHandlerRegistry handlerRegistry) {
|
||||
this.event = event;
|
||||
this.handlerRegistry = handlerRegistry;
|
||||
if (System.getProperty("cellar.timeout") != null) {
|
||||
try {
|
||||
this.timeout = Long.parseLong(System.getProperty("cellar.timeout"));
|
||||
} catch (Exception e) {
|
||||
this.timeout = DEFAULT_TIMEOUT;
|
||||
}
|
||||
} else {
|
||||
this.timeout = DEFAULT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
public LocalEventDispatchTask(E event, EventHandlerRegistry handlerRegistry, long timeout) {
|
||||
this.event = event;
|
||||
this.handlerRegistry = handlerRegistry;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public LocalEventDispatchTask(EventHandlerRegistry handlerRegistry, long timeout, long interval, E event) {
|
||||
this.handlerRegistry = handlerRegistry;
|
||||
this.timeout = timeout;
|
||||
this.interval = interval;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
boolean dispatched = false;
|
||||
|
||||
for (long delay = 0; delay < timeout && !dispatched; delay += interval) {
|
||||
EventHandler handler = handlerRegistry.getHandler(event);
|
||||
if (handler != null) {
|
||||
handler.handle(event);
|
||||
dispatched = true;
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(interval);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.warn("Interrupted while waiting for cluster event handler", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dispatched) {
|
||||
LOGGER.warn("Failed to retrieve handler for cluster event {}", event.getClass());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Error while dispatching task", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public long getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(long timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public long getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
public void setInterval(long interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
/*
|
||||
* 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 ru.entaxy.esb.platform.core.cluster.persistence.handler;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.karaf.cellar.core.event.Event;
|
||||
import org.apache.karaf.cellar.core.event.EventDispatcher;
|
||||
import org.apache.karaf.cellar.core.event.EventHandlerRegistry;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Event handler service registry dispatcher.
|
||||
*/
|
||||
public class LocalEventHandlerRegistryDispatcher<E extends Event> implements EventDispatcher<E> {
|
||||
|
||||
private static final transient Logger LOGGER = LoggerFactory.getLogger(LocalEventHandlerRegistryDispatcher.class);
|
||||
private ExecutorService threadPool;
|
||||
private EventHandlerRegistry handlerRegistry;
|
||||
|
||||
public void init() {
|
||||
if (threadPool == null) {
|
||||
if (Boolean.getBoolean(this.getClass().getName() + ".threadPool.singleThreadExecutor")) {
|
||||
LOGGER.info("Will use an Executor that uses a single worker thread");
|
||||
threadPool = Executors.newSingleThreadExecutor();
|
||||
} else {
|
||||
LOGGER.info("Will use an Executor with a pool of threads");
|
||||
threadPool = Executors.newCachedThreadPool();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a cluster {@code Event} to the appropriate cluster {@code EventHandler}.
|
||||
*
|
||||
* @param event the cluster event to dispatch.
|
||||
*/
|
||||
public void dispatch(E event) {
|
||||
LocalEventDispatchTask task = new LocalEventDispatchTask(event, handlerRegistry);
|
||||
threadPool.execute(task);
|
||||
}
|
||||
|
||||
public EventHandlerRegistry getHandlerRegistry() {
|
||||
return handlerRegistry;
|
||||
}
|
||||
|
||||
public void setHandlerRegistry(EventHandlerRegistry handlerRegistry) {
|
||||
this.handlerRegistry = handlerRegistry;
|
||||
}
|
||||
|
||||
public ExecutorService getThreadPool() {
|
||||
return threadPool;
|
||||
}
|
||||
|
||||
public void setThreadPool(ExecutorService threadPool) {
|
||||
this.threadPool = threadPool;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (threadPool != null) {
|
||||
threadPool.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence.handler;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.karaf.cellar.core.event.Event;
|
||||
import org.apache.karaf.cellar.core.event.EventHandler;
|
||||
import org.apache.karaf.cellar.core.event.EventHandlerRegistry;
|
||||
|
||||
public class LocalHandlerRegistry<E extends Event> implements EventHandlerRegistry<E> {
|
||||
|
||||
private Map<Class,EventHandler> eventHandlerMap = new ConcurrentHashMap<Class,EventHandler>();
|
||||
|
||||
@Override
|
||||
public EventHandler<E> getHandler(E event) {
|
||||
return eventHandlerMap.get(event.getClass());
|
||||
}
|
||||
|
||||
public void addHandler(EventHandler eventHandler) {
|
||||
eventHandlerMap.put(eventHandler.getType(), eventHandler);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,185 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
/*
|
||||
* 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 ru.entaxy.esb.platform.core.cluster.persistence.handler;
|
||||
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.ITopic;
|
||||
import com.hazelcast.core.Message;
|
||||
import com.hazelcast.core.MessageListener;
|
||||
import org.apache.karaf.cellar.core.Configurations;
|
||||
import org.apache.karaf.cellar.core.Dispatcher;
|
||||
import org.apache.karaf.cellar.core.Node;
|
||||
import org.apache.karaf.cellar.core.control.BasicSwitch;
|
||||
import org.apache.karaf.cellar.core.control.Switch;
|
||||
import org.apache.karaf.cellar.core.control.SwitchStatus;
|
||||
import org.apache.karaf.cellar.core.event.Event;
|
||||
import org.apache.karaf.cellar.core.event.EventConsumer;
|
||||
import org.apache.karaf.cellar.hazelcast.Constants;
|
||||
import org.osgi.service.cm.Configuration;
|
||||
import org.osgi.service.cm.ConfigurationAdmin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Consumes messages from the Hazelcast {@code ITopic} and calls the {@code EventDispatcher}.
|
||||
*/
|
||||
public class LocalTopicConsumer<E extends Event> implements EventConsumer<E>, MessageListener<E> {
|
||||
|
||||
private static final transient Logger log = LoggerFactory.getLogger(LocalTopicConsumer.class);
|
||||
|
||||
public static final String SWITCH_ID = "org.apache.karaf.cellar.topic.consumer";
|
||||
|
||||
private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
|
||||
|
||||
private String registrationId;
|
||||
private HazelcastInstance instance;
|
||||
private ITopic topic;
|
||||
private Dispatcher dispatcher;
|
||||
private Node node;
|
||||
private ConfigurationAdmin configurationAdmin;
|
||||
|
||||
private boolean isConsuming;
|
||||
|
||||
public void init() {
|
||||
if (topic == null) {
|
||||
topic = instance.getTopic(Constants.TOPIC);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume(E event) {
|
||||
// check if event has a specified destination.
|
||||
if ((event.getDestination() == null || event.getDestination().contains(node)) && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) {
|
||||
log.info("==>> EVENT TO PROCESS");
|
||||
dispatcher.dispatch(event);
|
||||
} else {
|
||||
if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) {
|
||||
log.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
isConsuming = true;
|
||||
if (topic != null) {
|
||||
registrationId = topic.addMessageListener(this);
|
||||
} else {
|
||||
topic = instance.getTopic(Constants.TOPIC);
|
||||
registrationId = topic.addMessageListener(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
isConsuming = false;
|
||||
if (topic != null) {
|
||||
topic.removeMessageListener(registrationId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isConsuming() {
|
||||
return isConsuming;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Message<E> message) {
|
||||
consume(message.getMessageObject());
|
||||
}
|
||||
|
||||
public Dispatcher getDispatcher() {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
public void setDispatcher(Dispatcher dispatcher) {
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public HazelcastInstance getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setInstance(HazelcastInstance instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public ITopic getTopic() {
|
||||
return topic;
|
||||
}
|
||||
|
||||
public void setTopic(ITopic topic) {
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Switch getSwitch() {
|
||||
// load the switch status from the config
|
||||
try {
|
||||
Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null);
|
||||
if (configuration != null) {
|
||||
Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.CONSUMER));
|
||||
if (status) {
|
||||
eventSwitch.turnOn();
|
||||
} else {
|
||||
eventSwitch.turnOff();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return eventSwitch;
|
||||
}
|
||||
|
||||
public Node getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setNode(Node node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public ConfigurationAdmin getConfigurationAdmin() {
|
||||
return configurationAdmin;
|
||||
}
|
||||
|
||||
public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
|
||||
this.configurationAdmin = configurationAdmin;
|
||||
}
|
||||
|
||||
}
|
18
platform/runtime/core/cluster/pom.xml
Normal file
18
platform/runtime/core/cluster/pom.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>cluster</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>ENTAXY :: PLATFORM :: CORE :: CLUSTER</name>
|
||||
<description>ENTAXY :: PLATFORM :: CORE :: CLUSTER</description>
|
||||
|
||||
|
||||
<modules>
|
||||
<module>cluster-persistence-service</module>
|
||||
</modules>
|
||||
</project>
|
Reference in New Issue
Block a user