imdg = new ImdgHazelcast<>();
+ imdg.setMap(getHazelcast().getMap(key));
+ return imdg;
+ }
+
+ // @Override
+ public void waitTillReadyState() throws InterruptedException {
+ boolean done = false;
+ int sleepCount = 0;
+ while (!done) {
+ try {
+ HazelcastInstance instance = getHazelcast();
+ if (instance != null) {
+ HazelcastHelper.otcSystem_waitTillReadyState(instance);
+ done = true;
+ break;
+ } else {
+ if (sleepCount++ % 30 == 0)
+ log.debug("Hazelcast not connected. Wait till STORAGE be ready...");
+ }
+ } catch (InterruptedException e) {
+ log.warn(String.format("Waiting Hazelcast interrupted: %s -> %s", e.getClass().getSimpleName(), e.getMessage()));
+ throw e;
+ }
+ Thread.sleep(100);
+ }
+ }
+
+// @Override
+ public void shutdown() {
+ isAvailableNow = false;
+ if (hazelcastInstance != null)
+ hazelcastInstance.shutdown();
+ }
+
+ public String getMapNameForCache() {
+ return mapNameForCache;
+ }
+
+ public void setMapNameForCache(String mapNameForCache) {
+ this.mapNameForCache = mapNameForCache;
+ }
+}
+
diff --git a/platform-parent/platform-imdg-api-hazelcast-impl/src/main/java/ru/spcex/platform/imdg/iml/hazelcast/service/IHazelcastClusterStatus.java b/platform-parent/platform-imdg-api-hazelcast-impl/src/main/java/ru/spcex/platform/imdg/iml/hazelcast/service/IHazelcastClusterStatus.java
new file mode 100644
index 000000000..258430164
--- /dev/null
+++ b/platform-parent/platform-imdg-api-hazelcast-impl/src/main/java/ru/spcex/platform/imdg/iml/hazelcast/service/IHazelcastClusterStatus.java
@@ -0,0 +1,10 @@
+package ru.spcex.platform.imdg.iml.hazelcast.service;
+
+import com.hazelcast.core.HazelcastInstance;
+
+public interface IHazelcastClusterStatus {
+ void getAvailable(HazelcastInstance hazelcastNotInited);
+
+ void getUnavailable(HazelcastInstance hazelcastNotInited);
+
+}
diff --git a/platform-parent/platform-imdg-api-hazelcast-impl/src/main/java/ru/spcex/platform/imdg/iml/hazelcast/util/HazelcastHelper.java b/platform-parent/platform-imdg-api-hazelcast-impl/src/main/java/ru/spcex/platform/imdg/iml/hazelcast/util/HazelcastHelper.java
new file mode 100644
index 000000000..14b9f3394
--- /dev/null
+++ b/platform-parent/platform-imdg-api-hazelcast-impl/src/main/java/ru/spcex/platform/imdg/iml/hazelcast/util/HazelcastHelper.java
@@ -0,0 +1,130 @@
+package ru.spcex.platform.imdg.iml.hazelcast.util;
+
+import com.hazelcast.client.HazelcastClient;
+import com.hazelcast.client.config.ClientConfig;
+import com.hazelcast.client.config.ClientNetworkConfig;
+import com.hazelcast.config.NearCacheConfig;
+import com.hazelcast.core.HazelcastException;
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.IMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class HazelcastHelper {
+ private static final Logger log = LoggerFactory.getLogger(HazelcastHelper.class);
+
+ public static final int DEFAULT_CONNECTION_TIMEOUT_SEC = 30;
+ public static final int DEFAULT_CONNECTION_ATTEMPT_PERIOD_SEC = 10;
+ public static final int DEFAULT_CONNECTION_ATTEMPT_LIMIT = Integer.MAX_VALUE;
+ public static final int TEST_CONNECTION_ATTEMPT_LIMIT = 1;
+ public static final String OTC_SYSTEM_MAP = "OTC_SYSTEM";
+
+ public static ClientConfig getClientConfig(String members, String login, String password, String instanceName) {
+ return getClientConfig(members, login, password, instanceName, null);
+ }
+
+ public static ClientConfig getClientConfig(String members, String login, String password, String instanceName, NearCacheConfig nearCacheConfig) {
+ if (members == null) {
+ throw new IllegalArgumentException("members must not be null!");
+ }
+ String[] mm = members.split(",");
+ if (mm.length == 0) {
+ throw new IllegalArgumentException("members must not be empty!");
+ }
+ ClientNetworkConfig clientNetworkConfig = new ClientNetworkConfig();
+ for (String m : mm) {
+ if (m != null && !m.isEmpty()) {
+ clientNetworkConfig.addAddress(m);
+ }
+ }
+ ClientConfig config = new ClientConfig();
+ config.setInstanceName(instanceName);
+ config.setNetworkConfig(clientNetworkConfig);
+
+ config.setProperty("hazelcast.logging.type", "slf4j");
+
+ config.getGroupConfig().setName(login);
+ config.getGroupConfig().setPassword(password);
+
+ config.getNetworkConfig().setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_SEC * 1000);
+ config.getNetworkConfig().setConnectionAttemptPeriod(DEFAULT_CONNECTION_ATTEMPT_PERIOD_SEC * 1000);
+ config.getNetworkConfig().setConnectionAttemptLimit(DEFAULT_CONNECTION_ATTEMPT_LIMIT);
+
+ if (nearCacheConfig != null) config.addNearCacheConfig(nearCacheConfig);
+ return config;
+ }
+
+
+ /**
+ * Создаёт клиента HazelcastInstance, подключённого по настрйокам ClientConfig.
+ * Ожидает готовности Storage, инициализирует TextErrorService.
+ * В случае ошибок делает повторение попыток создания клиента.
+ *
+ * Пример получения ClientConfig:
+ *
+ * HazelcastHelper.getClientConfig(
+ * Config.get().getHazelcastSettings().getClusterMembers(),
+ * Config.get().getHazelcastSettings().getLogin(),
+ * Config.get().getHazelcastSettings().getPassword()
+ * )
+ *
+ *
+ * @param hzClientConfig
+ * @return HazelcastClient
+ */
+ public HazelcastInstance makeHazelcastClientAndWaitTillReady(ClientConfig hzClientConfig) {
+ HazelcastInstance instance = null;
+ // ожидание инициализации Storage (только после инициализации IDGenerator начинать работу).
+ boolean done = false;
+ while (!done) {
+ try {
+ instance = HazelcastClient.newHazelcastClient(hzClientConfig);// createHzClient();
+ otcSystem_waitTillReadyState(instance);
+// TextErrorService.setHazelcast(instance);
+ log.info("Hazelcast: TextErrorService done");
+ done = true;
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Thread interrupted when waiting storage ready.", e);
+ } catch (Exception e) {
+ log.info(String.format("Waiting Hazelcast: %s -> %s", e.getClass().getSimpleName(), e.getMessage()));
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ignored) {
+ throw new RuntimeException("Thread interrupted.", e);
+ }
+ }
+ }
+ // проверка версии классов
+// HazelcastCommon.verifyVersionClientsClasses(instance);
+ return instance;
+ }
+
+ public static void otcSystem_waitTillReadyState(HazelcastInstance hazelcast) throws InterruptedException {
+ int sleepCount = 0;
+ try {
+ while (!otcSystem_getStorageState(hazelcast)) {
+ if (sleepCount++ % 30 == 0)
+ log.info("Wait till STORAGE be ready...");
+ Thread.sleep(100);
+ }
+ } catch (HazelcastException hcEx) {
+ // проброс InterruptException из Hazelcast
+ if (hcEx instanceof HazelcastException && hcEx.getCause() instanceof InterruptedException)
+ throw new InterruptedException("Can not obtain storage for check state, cause has interrupted. " + hcEx);
+ throw hcEx;
+ }
+ }
+
+ public static boolean otcSystem_getStorageState(HazelcastInstance hazelcast) {
+ IMap systemMap = hazelcast.getMap(OTC_SYSTEM_MAP);
+ return Boolean.valueOf(systemMap.get("STORAGE.STATE"));
+ }
+
+ public static void otcSystem_setStorageState(boolean val, HazelcastInstance hazelcast) {
+ IMap systemMap = hazelcast.getMap(OTC_SYSTEM_MAP);
+ systemMap.set("STORAGE.STATE", Boolean.toString(val));
+ }
+
+
+
+}
diff --git a/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/Imdg.java b/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/Imdg.java
new file mode 100644
index 000000000..259d607b6
--- /dev/null
+++ b/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/Imdg.java
@@ -0,0 +1,47 @@
+package ru.spcex.platform.imdg.api;
+
+import ru.spcex.platform.classes.base.SpcexObjectBase;
+
+import java.util.Collection;
+
+public interface Imdg {
+ default void insert(T paramT) {
+ throw new UnsupportedOperationException("not implemented insert");
+ }
+
+ default void update(T paramT) {
+ throw new UnsupportedOperationException("not implemented update");
+ }
+
+ default void delete(T paramT) {
+ throw new UnsupportedOperationException("not implemented delete");
+ }
+
+ default Long nextIDSequenceFor() {
+ throw new UnsupportedOperationException("not implemented nextIDSequenceFor");
+ }
+
+ default Collection getCollectionObjectsBySQL(String paramString) {
+ throw new UnsupportedOperationException("not implemented getCollectionObjectsBySQL");
+ }
+
+ default T getSingleObjectBySQL(String paramString) {
+ throw new UnsupportedOperationException("not implemented getSingleObjectBySQL");
+ }
+
+ default T getSingleObjectByID(Long paramLong) {
+ throw new UnsupportedOperationException("not implemented getSingleObjectByID");
+ }
+
+ default Collection getCollectionIdsBySQL(String paramString) {
+ throw new UnsupportedOperationException("not implemented getCollectionIdsBySQL");
+ }
+
+ default Collection getAllValues() {
+ throw new UnsupportedOperationException("not implemented getAllValues");
+ }
+
+ default Collection projectionsAttributeBySql(String paramString, String... paramVarArgs) {
+ throw new UnsupportedOperationException("not implemented projectionsAttributeBySql");
+ }
+}
diff --git a/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/ImdgProvider.java b/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/ImdgProvider.java
new file mode 100644
index 000000000..89b1f3f6d
--- /dev/null
+++ b/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/ImdgProvider.java
@@ -0,0 +1,11 @@
+package ru.spcex.platform.imdg.api;
+
+import ru.spcex.platform.classes.base.SpcexObjectBase;
+
+public interface ImdgProvider {
+ /**
+ * пока простой интерфейс для получения доступа к мапам
+ */
+ public Imdg getImdg(String key, Class clazz);
+
+}
diff --git a/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/Storage.java b/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/Storage.java
deleted file mode 100644
index 8726f045f..000000000
--- a/platform-parent/platform-imdg-api/src/main/java/ru/spcex/platform/imdg/api/Storage.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package ru.spcex.platform.imdg.api;
-
-import ru.spcex.platform.classes.base.SpcexObjectBase;
-
-import java.util.Collection;
-
-public interface Storage {
- void insert(Class paramClass, T paramT);
-
- void update(Class paramClass, T paramT);
-
- void delete(Class paramClass, T paramT);
-
- Long nextIDSequenceFor();
-
- Collection getCollectionObjectsBySQL(Class paramClass, String paramString);
-
- T getSingleObjectBySQL(Class paramClass, String paramString);
-
- T getSingleObjectByID(Class paramClass, Long paramLong);
-
- Collection getCollectionIdsBySQL(Class paramClass, String paramString);
-
- Collection getAllValues(Class paramClass);
-
- Collection projectionsAttributeBySql(Class paramClass, String paramString, String... paramVarArgs);
-}
diff --git a/platform-parent/platform-utils/pom.xml b/platform-parent/platform-utils/pom.xml
new file mode 100644
index 000000000..b9e306f5e
--- /dev/null
+++ b/platform-parent/platform-utils/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+ platform-utils
+ Platform utilities
+ jar
+ 1.0.0
+
+
+ platform-parent
+ ru.spcex.platform
+ 1.0.0
+
+
+
+ 17
+ 17
+
+
+
\ No newline at end of file
diff --git a/platform-parent/platform-utils/src/main/java/ru/spcex/platform/utils/log/ExceptionUtils.java b/platform-parent/platform-utils/src/main/java/ru/spcex/platform/utils/log/ExceptionUtils.java
new file mode 100644
index 000000000..27bfe411b
--- /dev/null
+++ b/platform-parent/platform-utils/src/main/java/ru/spcex/platform/utils/log/ExceptionUtils.java
@@ -0,0 +1,13 @@
+package ru.spcex.platform.utils.log;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public class ExceptionUtils {
+ public static String getStackTrace(Throwable throwable) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw, true);
+ throwable.printStackTrace(pw);
+ return sw.getBuffer().toString();
+ }
+}
diff --git a/platform-parent/pom.xml b/platform-parent/pom.xml
index 83cf3032b..a9dae8e33 100644
--- a/platform-parent/pom.xml
+++ b/platform-parent/pom.xml
@@ -20,5 +20,7 @@
platform-imdg-api
platform-classes-base
+ platform-imdg-api-hazelcast-impl
+ platform-utils
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index fc38f55cd..f7aa5a677 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,10 +31,13 @@
${folder_root_clearing_temp}
${folder_root_clearing}/clearing-parent/backend-api
+ ${folder_root_clearing}/clearing-parent/imdg
${folder_root_clearing}/clearing-parent/dbf-exporter
${folder_root_clearing}/clearing-parent/dbf-importer
3.12.4
+ 1.7.33
+ 1.2.10
@@ -52,6 +55,11 @@
backend-api
${global.project.version}
+
+ ru.spcex.clearing
+ imdg
+ ${global.project.version}
+
ru.spcex.clearing
classes
@@ -73,6 +81,19 @@
platform-classes-base
1.0.0
+
+
+ ru.spcex.platform
+ platform-imdg-api-hazelcast-impl
+ 1.0.0
+
+
+
+ ru.spcex.platform
+ platform-utils
+ 1.0.0
+
+
ru.spcex.platform
platform-imdg-api
diff --git a/z-distr/pom.xml b/z-distr/pom.xml
index 87d3bd5ea..dc9f8327c 100644
--- a/z-distr/pom.xml
+++ b/z-distr/pom.xml
@@ -23,6 +23,10 @@
ru.spcex.clearing
backend-api
+
+ ru.spcex.clearing
+ imdg
+
@@ -106,6 +110,25 @@
+
+ copy-imdg-bin
+ prepare-package
+
+ copy
+
+
+
+
+ ${folder_root_clearing_imdg}/target/jar/imdg-exec.jar
+ ${folder.clearing.distr.modules}/imdg/imdg-exec.jar
+
+
+ ${folder_root_clearing_imdg}/src/main/resources/application.properties
+ ${folder.clearing.distr.modules}/imdg/application.properties
+
+
+
+
copy-dbf-exporter-bin