├── HCPrject.md ├── my-first-service.md ├── src ├── test │ ├── resources │ │ ├── invoice.csv │ │ ├── detail.csv │ │ └── hello.py │ └── java │ │ └── org │ │ └── hcjf │ │ ├── cloud │ │ └── DistributedLayerTest.java │ │ ├── utils │ │ ├── SetNullTest.java │ │ ├── NamedUuidTest.java │ │ ├── CryptographyTestSuite.java │ │ └── TTLMapTest.java │ │ ├── io │ │ ├── net │ │ │ └── http │ │ │ │ ├── ContextTest.java │ │ │ │ ├── HttpSimpleServer.java │ │ │ │ └── Http2Test.java │ │ └── process │ │ │ └── ProcessServiceTest.java │ │ └── layers │ │ ├── cache │ │ ├── SubLayerCache.java │ │ ├── SubLayerCache2.java │ │ ├── MapCache.java │ │ └── Main.java │ │ └── scripting │ │ └── PythonCodeTest.java └── main │ ├── resources │ └── org │ │ └── hcjf │ │ └── io │ │ └── net │ │ └── https │ │ ├── client.jks │ │ ├── server.cer │ │ ├── cacerts.jks │ │ ├── keystore.jks │ │ ├── trustedCerts.jks │ │ └── README.txt │ └── java │ └── org │ └── hcjf │ ├── service │ ├── ServiceConsumer.java │ ├── security │ │ ├── SuperClassPermission.java │ │ ├── Permissions.java │ │ ├── LazyPermissions.java │ │ ├── Permission.java │ │ └── LazyPermission.java │ └── ServiceThreadGroup.java │ ├── layers │ ├── distributed │ │ ├── DistributedLayerInterface.java │ │ └── DistributedLayer.java │ ├── query │ │ ├── model │ │ │ ├── QueryOrderParameter.java │ │ │ ├── QueryReturnParameter.java │ │ │ ├── QueryComponent.java │ │ │ ├── QueryTextResource.java │ │ │ ├── QueryId.java │ │ │ ├── QueryConditional.java │ │ │ ├── QueryOrderField.java │ │ │ ├── QueryOrderFunction.java │ │ │ ├── QueryReturnField.java │ │ │ ├── QueryBsonBuilderLayer.java │ │ │ ├── QueryDynamicResource.java │ │ │ ├── QueryJsonResource.java │ │ │ ├── QueryReturnLiteral.java │ │ │ ├── QueryFunction.java │ │ │ ├── QueryResource.java │ │ │ ├── QueryReturnFunction.java │ │ │ ├── QueryReturnConditional.java │ │ │ └── QueryReturnUnprocessedValue.java │ │ ├── evaluators │ │ │ ├── GreaterThanOrEqual.java │ │ │ ├── SmallerThanOrEqual.java │ │ │ ├── NotIn.java │ │ │ ├── TrueEvaluator.java │ │ │ ├── Evaluator.java │ │ │ ├── Distinct.java │ │ │ ├── Not.java │ │ │ ├── And.java │ │ │ ├── Or.java │ │ │ └── BooleanEvaluator.java │ │ ├── serializer │ │ │ └── QuerySerializer.java │ │ ├── compilers │ │ │ └── QueryCompiler.java │ │ ├── functions │ │ │ ├── QueryFunctionLayerInterface.java │ │ │ ├── QueryAggregateFunctionLayerInterface.java │ │ │ ├── GetIndexQueryFunctionLayer.java │ │ │ ├── EvalExpressionAggregateFunctionLayer.java │ │ │ ├── ContextAggregateFunction.java │ │ │ ├── BaseQueryAggregateFunctionLayer.java │ │ │ ├── MinAggregateFunctionLayer.java │ │ │ ├── DistinctQueryAggregateFunction.java │ │ │ ├── BaseFunctionLayer.java │ │ │ ├── AddAggregateFunction.java │ │ │ ├── CountQueryAggregateFunctionLayer.java │ │ │ └── PutAggregateFunction.java │ │ ├── Joinable.java │ │ ├── Groupable.java │ │ └── Enlarged.java │ ├── plugins │ │ ├── PluginLayer.java │ │ ├── PluginClassLoader.java │ │ └── Plugin.java │ ├── crud │ │ ├── command │ │ │ ├── ResourceCommandLayerInterface.java │ │ │ ├── ResourceCommandLayer.java │ │ │ └── CommandRequestModel.java │ │ ├── ReadRowsLayerInterface.java │ │ ├── References.java │ │ ├── IdentifiableLayerInterface.java │ │ ├── CreateLayerInterface.java │ │ ├── DeleteLayerInterface.java │ │ ├── ReadLayerInterface.java │ │ └── UpdateLayerInterface.java │ ├── locale │ │ ├── LocaleLayerInterface.java │ │ ├── DefaultLocaleLayer.java │ │ └── PropertiesFileLocaleLayer.java │ ├── AdaptableLayer.java │ ├── cache │ │ ├── CacheServiceConsumer.java │ │ └── CacheLayerInterface.java │ ├── scripting │ │ ├── CodeEvaluator.java │ │ ├── PythonCodeEvaluator.java │ │ └── ExecutionResult.java │ ├── DefaultLayer.java │ ├── resources │ │ ├── Resourceable.java │ │ └── Resource.java │ ├── LayerInterface.java │ └── LayerProxy.java │ ├── cloud │ ├── impl │ │ ├── objects │ │ │ ├── DistributedObject.java │ │ │ ├── LocalLeaf.java │ │ │ ├── RemoteLeaf.java │ │ │ ├── DistributedLock.java │ │ │ └── DistributedLeaf.java │ │ ├── messages │ │ │ ├── KeepAliveMessage.java │ │ │ ├── AckMessage.java │ │ │ ├── TestNodeMessage.java │ │ │ ├── ShutdownMessage.java │ │ │ ├── PublishPluginMessage.java │ │ │ ├── InvokeMessage.java │ │ │ ├── UnlockMessage.java │ │ │ ├── HidePathMessage.java │ │ │ ├── PublishPathMessage.java │ │ │ ├── MethodResponseMessage.java │ │ │ ├── EventMessage.java │ │ │ ├── BusyNodeMessage.java │ │ │ ├── NodeIdentificationMessage.java │ │ │ ├── LockMessage.java │ │ │ ├── SignalMessage.java │ │ │ ├── SignalAllMessage.java │ │ │ ├── PublishLayerMessage.java │ │ │ ├── MethodInvokeMessage.java │ │ │ ├── ServiceDefinitionResponseMessage.java │ │ │ ├── ServiceDefinitionMessage.java │ │ │ └── LayerInvokeMessage.java │ │ └── network │ │ │ ├── CloudSession.java │ │ │ ├── NetworkComponent.java │ │ │ ├── CloudServer.java │ │ │ ├── CloudClient.java │ │ │ └── DistributedLayerRegistry.java │ ├── CloudConsumer.java │ ├── counter │ │ └── Counter.java │ └── cache │ │ └── CloudCacheStrategy.java │ ├── io │ ├── console │ │ ├── messages │ │ │ ├── GetMetadataMessage.java │ │ │ ├── LoadPluginMessage.java │ │ │ ├── EvaluateQueryableMessage.java │ │ │ ├── LoginMessage.java │ │ │ └── ExecuteMessage.java │ │ ├── ConsoleSession.java │ │ ├── ConsoleCommandLayerInterface.java │ │ ├── SessionMetadata.java │ │ └── ServerMetadata.java │ ├── net │ │ ├── http │ │ │ ├── HttpVersion.java │ │ │ ├── layered │ │ │ │ ├── LayeredRequest.java │ │ │ │ └── LayeredResponse.java │ │ │ ├── proxy │ │ │ │ ├── ProxyTask.java │ │ │ │ ├── HttpProxyRule.java │ │ │ │ └── RedirectionRule.java │ │ │ ├── http2 │ │ │ │ └── frames │ │ │ │ │ ├── PingFrame.java │ │ │ │ │ ├── HeadersFrame.java │ │ │ │ │ ├── PriorityFrame.java │ │ │ │ │ ├── PushPromiseFrame.java │ │ │ │ │ ├── RstStreamFrame.java │ │ │ │ │ ├── ContinuationFrame.java │ │ │ │ │ ├── WindowsUpdateFrame.java │ │ │ │ │ ├── DataFrame.java │ │ │ │ │ └── GoAwayFrame.java │ │ │ ├── RequestBodyDecoderLayer.java │ │ │ ├── datasources │ │ │ │ └── DataSourceServiceConsumer.java │ │ │ ├── Cookie2.java │ │ │ └── pipeline │ │ │ │ └── MultipartHttpPipelineResponse.java │ │ ├── messages │ │ │ ├── MessageCollection.java │ │ │ ├── NetUtils.java │ │ │ ├── EncryptedMessage.java │ │ │ └── ResponseMessage.java │ │ ├── proxy │ │ │ └── TcpProxySession.java │ │ ├── NetClient.java │ │ ├── kubernetes │ │ │ └── artifacts │ │ │ │ ├── KubernetesJobResource.java │ │ │ │ ├── KubernetesDeploymentResource.java │ │ │ │ ├── KubernetesCronJobResource.java │ │ │ │ └── KubernetesServiceResource.java │ │ └── broadcast │ │ │ └── BroadcastConsumer.java │ └── process │ │ └── ProcessDiscoveryConsumer.java │ ├── events │ ├── StoreStrategyLayerInterface.java │ ├── Event.java │ ├── RemoteEvent.java │ ├── DistributedEvent.java │ └── EventListener.java │ ├── properties │ ├── IllegalPropertyValueException.java │ └── PropertyValueValidator.java │ ├── errors │ ├── HCJFRemoteException.java │ ├── HCJFSecurityException.java │ ├── HCJFServiceTimeoutException.java │ ├── HCJFRemoteInvocationTimeoutException.java │ ├── TaggedException.java │ └── HCJFRuntimeException.java │ ├── log │ ├── LogPrinter.java │ ├── debug │ │ ├── Agent.java │ │ └── Agents.java │ └── LogMessages.java │ ├── utils │ ├── bson │ │ └── BsonCustomBuilderLayer.java │ ├── MatrixBsonBuilderLayer.java │ ├── io │ │ └── net │ │ │ └── http │ │ │ └── HttpUtils.java │ └── TtlCollection.java │ └── names │ └── NamingConsumer.java ├── examples └── org │ └── hcjf │ └── examples │ └── salary │ ├── ItemCalculator.java │ ├── Main.java │ ├── SaludCalculator.java │ └── EmployeeResource.java ├── .travis ├── deploy.sh └── settings.xml ├── .gitlab-ci.yml ├── settings.xml ├── README.md ├── getting-started.md └── .github └── workflows └── jfrog.yaml /HCPrject.md: -------------------------------------------------------------------------------- 1 | #Proyecto Holanda Catalina -------------------------------------------------------------------------------- /my-first-service.md: -------------------------------------------------------------------------------- 1 | # My first service -------------------------------------------------------------------------------- /src/test/resources/invoice.csv: -------------------------------------------------------------------------------- 1 | id,date,total 2 | 1,2019-07-10 00:00:00,55 3 | 2,2019-07-10 00:00:00,100 4 | 3,2019-07-10 00:00:00,150 5 | -------------------------------------------------------------------------------- /src/main/resources/org/hcjf/io/net/https/client.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaito/HolandaCatalinaFw/HEAD/src/main/resources/org/hcjf/io/net/https/client.jks -------------------------------------------------------------------------------- /src/main/resources/org/hcjf/io/net/https/server.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaito/HolandaCatalinaFw/HEAD/src/main/resources/org/hcjf/io/net/https/server.cer -------------------------------------------------------------------------------- /src/main/resources/org/hcjf/io/net/https/cacerts.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaito/HolandaCatalinaFw/HEAD/src/main/resources/org/hcjf/io/net/https/cacerts.jks -------------------------------------------------------------------------------- /src/main/resources/org/hcjf/io/net/https/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaito/HolandaCatalinaFw/HEAD/src/main/resources/org/hcjf/io/net/https/keystore.jks -------------------------------------------------------------------------------- /src/main/resources/org/hcjf/io/net/https/trustedCerts.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaito/HolandaCatalinaFw/HEAD/src/main/resources/org/hcjf/io/net/https/trustedCerts.jks -------------------------------------------------------------------------------- /src/test/resources/detail.csv: -------------------------------------------------------------------------------- 1 | id,idInvoice,detail,amount 2 | 1,1,Thing 1,50 3 | 2,1,Thing 2,5 4 | 3,2,Thing 1,50 5 | 4,2,Thing 3,50 6 | 5,3,Thing 1,50 7 | 6,3,Thing 4,100 8 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/service/ServiceConsumer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.service; 2 | 3 | /** 4 | * This class is the super class of the all service 5 | * consumer. 6 | * @author javaito 7 | * 8 | */ 9 | public interface ServiceConsumer { 10 | } 11 | -------------------------------------------------------------------------------- /src/test/resources/hello.py: -------------------------------------------------------------------------------- 1 | properties = { 2 | "Key1": "value1", 3 | "key2": 3.5 4 | } 5 | 6 | if properties["Key1"] == "value1": 7 | print("El valor era correcto") 8 | 9 | result = properties["key2"] + 5 10 | print(properties["key2"] + 5) 11 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/cloud/DistributedLayerTest.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | /** 6 | * @author javaito 7 | */ 8 | public interface DistributedLayerTest extends LayerInterface { 9 | 10 | String method(String value); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/distributed/DistributedLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.distributed; 2 | 3 | /** 4 | * If some layer implements this interface then this layer will be distributed into the cloud. 5 | * @author javaito 6 | */ 7 | public interface DistributedLayerInterface { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/objects/DistributedObject.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.objects; 2 | 3 | /** 4 | * @author javaito 5 | */ 6 | public interface DistributedObject { 7 | 8 | Object getKey(); 9 | 10 | Object getInstance(); 11 | 12 | Long getLastUpdate(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryOrderParameter.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | public interface QueryOrderParameter extends QueryComponent { 4 | 5 | /** 6 | * Return the desc property. 7 | * @return Desc property. 8 | */ 9 | boolean isDesc(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/CloudConsumer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud; 2 | 3 | import org.hcjf.service.ServiceConsumer; 4 | 5 | /** 6 | * Consumer implementation for the cloud internal service. 7 | * @author javaito 8 | */ 9 | public abstract class CloudConsumer implements ServiceConsumer { 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/messages/GetMetadataMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | /** 6 | * This message is to make the server return the metadata. 7 | * @author javaito 8 | */ 9 | public class GetMetadataMessage extends Message { 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/events/StoreStrategyLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.events; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | public interface StoreStrategyLayerInterface extends LayerInterface { 6 | 7 | void storeEvent(DistributedEvent event); 8 | 9 | DistributedEvent restoreNext(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryReturnParameter.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | public interface QueryReturnParameter extends QueryComponent { 4 | 5 | /** 6 | * Return the field alias, can be null. 7 | * @return Field alias. 8 | */ 9 | String getAlias(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /examples/org/hcjf/examples/salary/ItemCalculator.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.examples.salary; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | import java.util.Map; 6 | 7 | public interface ItemCalculator extends LayerInterface { 8 | 9 | Map calculate(Map salary, String itemName); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/events/Event.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.events; 2 | 3 | /** 4 | * This class implements the system event structure. 5 | * @author javaito 6 | */ 7 | public interface Event { 8 | 9 | /** 10 | * Return the name of the event. 11 | * @return Event name. 12 | */ 13 | String getName(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/HttpVersion.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http; 2 | 3 | /** 4 | * Contains all the http version that the server support. 5 | */ 6 | public interface HttpVersion { 7 | 8 | String VERSION_1_0 = "HTTP/1.0"; 9 | 10 | String VERSION_1_1 = "HTTP/1.1"; 11 | 12 | String VERSION_2_0 = "HTTP/2.0"; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/GreaterThanOrEqual.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | /** 4 | * @author javaito 5 | * 6 | */ 7 | public class GreaterThanOrEqual extends GreaterThan { 8 | 9 | public GreaterThanOrEqual(Object leftValue, Object rightValue) { 10 | super(leftValue, rightValue, true); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/SmallerThanOrEqual.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | /** 4 | * @author javaito 5 | * 6 | */ 7 | public class SmallerThanOrEqual extends SmallerThan { 8 | 9 | public SmallerThanOrEqual(Object leftValue, Object rightValue) { 10 | super(leftValue, rightValue, true); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryComponent.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | /** 4 | * Group all the query components. 5 | */ 6 | public interface QueryComponent { 7 | 8 | /** 9 | * Verify if the component is underlying. 10 | * @return True if the component is underlying. 11 | */ 12 | boolean isUnderlying(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/KeepAliveMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class KeepAliveMessage extends Message { 11 | 12 | public KeepAliveMessage() { 13 | super(UUID.randomUUID()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/AckMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | /** 6 | * @author javaito 7 | */ 8 | public final class AckMessage extends Message { 9 | 10 | public AckMessage() {} 11 | 12 | public AckMessage(Message message) { 13 | super(message.getId()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /.travis/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | if [ ! -z "$TRAVIS_TAG" ] 3 | then 4 | echo "on a tag -> set pom.xml to $TRAVIS_TAG" 5 | mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=$TRAVIS_TAG 1>/dev/null 2>/dev/null 6 | else 7 | echo "not on a tag -> keep snapshot version in pom.xml" 8 | fi 9 | 10 | mvn clean deploy --settings .tratpvis/settings.xml -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/TestNodeMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class TestNodeMessage extends Message { 11 | 12 | public TestNodeMessage(UUID id) { 13 | super(id); 14 | } 15 | 16 | public TestNodeMessage() { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/org/hcjf/io/net/https/README.txt: -------------------------------------------------------------------------------- 1 | 2 | keytool -genkey -alias keyhcjf -keyalg RSA -keypass hcjfkeypassword -storepass hcjfkeystorepassword -keystore keystore.jks 3 | 4 | keytool -export -alias keyhcjf -storepass hcjfkeystorepassword -file server.cer -keystore keystore.jks 5 | 6 | keytool -import -v -trustcacerts -alias keyhcjf -file server.cer -keystore cacerts.jks -keypass hcjfkeypassword -storepass hcjfkeystorepassword -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/plugins/PluginLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.plugins; 2 | 3 | import org.hcjf.layers.Layer; 4 | 5 | /** 6 | * @author javaito 7 | */ 8 | public abstract class PluginLayer extends Layer { 9 | 10 | /** 11 | * Need obtain the invocation target to wrap the plugin. 12 | * @return Invation target. 13 | */ 14 | @Override 15 | protected abstract Object getTarget(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryTextResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | public class QueryTextResource extends QueryResource { 4 | 5 | private String text; 6 | 7 | public QueryTextResource(String resourceName, String text) { 8 | super(resourceName); 9 | this.text = text; 10 | } 11 | 12 | public String getText() { 13 | return text; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/process/ProcessDiscoveryConsumer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.process; 2 | 3 | import org.hcjf.service.ServiceConsumer; 4 | 5 | /** 6 | * @author javaito 7 | */ 8 | public interface ProcessDiscoveryConsumer extends ServiceConsumer { 9 | 10 | Boolean match(ProcessHandle processHandle); 11 | 12 | void onDiscovery(ProcessHandle processHandle); 13 | 14 | void onKill(ProcessHandle processHandle); 15 | } 16 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: maven:3-jdk-12 2 | 3 | cache: 4 | paths: 5 | - .m2/repository 6 | 7 | variables: 8 | MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository" 9 | 10 | test: 11 | script: "mvn test --settings settings.xml" 12 | 13 | deploy: 14 | script: 15 | - mvn deploy -Dversion="stk-$CI_COMMIT_TAG" --settings settings.xml -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dgpg.skip -P jfrog 16 | only: 17 | - tags 18 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/ShutdownMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.cloud.impl.network.CloudSession; 4 | import org.hcjf.io.net.messages.Message; 5 | 6 | /** 7 | * @author javaito 8 | */ 9 | public class ShutdownMessage extends Message { 10 | 11 | public ShutdownMessage() { 12 | } 13 | 14 | public ShutdownMessage(CloudSession node) { 15 | super(node.getId()); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/layered/LayeredRequest.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.layered; 2 | 3 | import org.hcjf.io.net.http.HttpRequest; 4 | 5 | /** 6 | * This class represents a package that contains all the 7 | * information about a restful request. 8 | * @author javaito 9 | */ 10 | public class LayeredRequest extends HttpRequest { 11 | 12 | public LayeredRequest(HttpRequest request) { 13 | super(request); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/messages/MessageCollection.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.messages; 2 | 3 | import java.util.Collection; 4 | 5 | public class MessageCollection extends Message { 6 | 7 | private Collection messages; 8 | 9 | public Collection getMessages() { 10 | return messages; 11 | } 12 | 13 | public void setMessages(Collection messages) { 14 | this.messages = messages; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/PublishPluginMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | /** 6 | * @author javaito 7 | */ 8 | public class PublishPluginMessage extends Message { 9 | 10 | private byte[] jarFile; 11 | 12 | public byte[] getJarFile() { 13 | return jarFile; 14 | } 15 | 16 | public void setJarFile(byte[] jarFile) { 17 | this.jarFile = jarFile; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/ConsoleSession.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console; 2 | 3 | import org.hcjf.io.net.NetServiceConsumer; 4 | import org.hcjf.io.net.NetSession; 5 | 6 | import java.util.UUID; 7 | 8 | /** 9 | * Default session for the console connection. 10 | * @author javaito 11 | */ 12 | public class ConsoleSession extends NetSession { 13 | 14 | public ConsoleSession(UUID id, NetServiceConsumer consumer) { 15 | super(id, consumer); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/properties/IllegalPropertyValueException.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.properties; 2 | 3 | /** 4 | * This exception is throws when the property value is not valid 5 | * @author javaito 6 | */ 7 | public final class IllegalPropertyValueException extends RuntimeException { 8 | 9 | /** 10 | * Constructor. 11 | * @param message Message. 12 | */ 13 | public IllegalPropertyValueException(String message) { 14 | super(message); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/errors/HCJFRemoteException.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.errors; 2 | 3 | public class HCJFRemoteException extends TaggedException { 4 | 5 | private static final String TAG = "REMOTE"; 6 | 7 | public HCJFRemoteException(String message, Object... params) { 8 | this(message, null, params); 9 | } 10 | 11 | public HCJFRemoteException(String message, Throwable cause, Object... params) { 12 | super(TAG, message, cause, params); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/serializer/QuerySerializer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.serializer; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.layers.query.Query; 5 | 6 | public interface QuerySerializer extends LayerInterface { 7 | 8 | /** 9 | * This method creates query expression from a query instance. 10 | * @param query Query instance. 11 | * @return Query expression. 12 | */ 13 | String serialize(Query query); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/errors/HCJFSecurityException.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.errors; 2 | 3 | public class HCJFSecurityException extends TaggedException { 4 | 5 | private static final String TAG = "SECURITY"; 6 | 7 | public HCJFSecurityException(String message, Object... params) { 8 | this(message, null, params); 9 | } 10 | 11 | public HCJFSecurityException(String message, Throwable cause, Object... params) { 12 | super(TAG, message, cause, params); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/compilers/QueryCompiler.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.compilers; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.layers.query.Query; 5 | 6 | public interface QueryCompiler extends LayerInterface { 7 | 8 | /** 9 | * Create a query instance from a expression. 10 | * @param queryExpression Expression that represents a query. 11 | * @return Query instance. 12 | */ 13 | Query compile(String queryExpression); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/errors/HCJFServiceTimeoutException.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.errors; 2 | 3 | public class HCJFServiceTimeoutException extends TaggedException { 4 | 5 | public static final String TAG = "SERVICE_TIMEOUT"; 6 | 7 | public HCJFServiceTimeoutException(String message, Object... params) { 8 | this(message, null, params); 9 | } 10 | 11 | public HCJFServiceTimeoutException(String message, Throwable cause, Object... params) { 12 | super(TAG, message, cause, params); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/objects/LocalLeaf.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.objects; 2 | 3 | /** 4 | * @author javaito 5 | */ 6 | public final class LocalLeaf extends DistributedLeaf { 7 | 8 | private Object instance; 9 | 10 | public LocalLeaf(Object key) { 11 | super(key); 12 | } 13 | 14 | @Override 15 | public final Object getInstance() { 16 | return instance; 17 | } 18 | 19 | public final void setInstance(Object instance) { 20 | this.instance = instance; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/plugins/PluginClassLoader.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.plugins; 2 | 3 | import java.net.URL; 4 | import java.net.URLClassLoader; 5 | 6 | /** 7 | * This class loader is a wrapper of url class loader. 8 | * @author javaito 9 | */ 10 | public class PluginClassLoader extends URLClassLoader { 11 | 12 | private final Plugin plugin; 13 | 14 | public PluginClassLoader(Plugin plugin, URL[] urls, ClassLoader parent) { 15 | super(urls, parent); 16 | this.plugin = plugin; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | jfrog-sitrack 8 | ${env.CI_JFROG_USERNAME} 9 | ${env.CI_JFROG_PASSWORD} 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/properties/PropertyValueValidator.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.properties; 2 | 3 | /** 4 | * This interface define the validators for the values of the properties. 5 | * @author javaito 6 | * 7 | */ 8 | public interface PropertyValueValidator { 9 | 10 | /** 11 | * This method is to validate the value to be returned 12 | * @param value Value to be returned 13 | * @return True if the value is valid and false if the value is not valid. 14 | */ 15 | public boolean validate(O value); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /examples/org/hcjf/examples/salary/Main.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.examples.salary; 2 | 3 | import org.hcjf.io.net.http.HttpServer; 4 | import org.hcjf.io.net.http.RestContext; 5 | import org.hcjf.layers.Layers; 6 | 7 | public class Main { 8 | 9 | public static void main(String[] args) { 10 | Layers.publishLayer(EmployeeResource.class); 11 | Layers.publishLayer(SalaryResource.class); 12 | HttpServer server = new HttpServer(9090); 13 | server.addContext(new RestContext("/api")); 14 | server.start(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/errors/HCJFRemoteInvocationTimeoutException.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.errors; 2 | 3 | public class HCJFRemoteInvocationTimeoutException extends TaggedException { 4 | 5 | private static final String TAG = "REMOTE_TIMEOUT"; 6 | 7 | public HCJFRemoteInvocationTimeoutException(String message, Object... params) { 8 | this(message, null, params); 9 | } 10 | 11 | public HCJFRemoteInvocationTimeoutException(String message, Throwable cause, Object... params) { 12 | super(TAG, message, cause, params); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/objects/RemoteLeaf.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.objects; 2 | 3 | /** 4 | * @author javaito 5 | */ 6 | public final class RemoteLeaf extends DistributedLeaf { 7 | 8 | private Object instance; 9 | 10 | public RemoteLeaf(Object key) { 11 | super(key); 12 | } 13 | 14 | @Override 15 | public Object getInstance() { 16 | return instance != null ? instance : this; 17 | } 18 | 19 | public final void setInstance(Object instance) { 20 | this.instance = instance; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/log/LogPrinter.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.log; 2 | 3 | import org.hcjf.service.ServiceConsumer; 4 | 5 | /** 6 | * This class porvide the interface to write the records of 7 | * the log in different places. 8 | * @author javaito 9 | * 10 | */ 11 | public interface LogPrinter extends ServiceConsumer { 12 | 13 | /** 14 | * This method must be the implementation in order to 15 | * print the record in the destiny. 16 | * @param record Rocord to print. 17 | */ 18 | public void print(Log.LogRecord record); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/NotIn.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | import org.hcjf.layers.query.Queryable; 4 | 5 | /** 6 | * @author javaito 7 | * 8 | */ 9 | public class NotIn extends In { 10 | 11 | public NotIn(Object leftValue, Object rightValue) { 12 | super(leftValue, rightValue); 13 | } 14 | 15 | @Override 16 | public boolean evaluate(Object object, Queryable.DataSource dataSource, Queryable.Consumer consumer) { 17 | return !super.evaluate(object, dataSource, consumer); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/command/ResourceCommandLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud.command; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Represents a single command to be executed when a PUT request is sent to a resource.
9 | * It should be associated with a specific resource and carry a single task, returning its corresponding result. 10 | */ 11 | public interface ResourceCommandLayerInterface extends LayerInterface { 12 | 13 | Map execute(Object payload); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/service/security/SuperClassPermission.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.service.security; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * This annotation receives as value the class with which to 10 | * create and to check the permissions of the invoked method. 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.METHOD) 14 | public @interface SuperClassPermission { 15 | Class value(); 16 | } -------------------------------------------------------------------------------- /src/main/java/org/hcjf/service/security/Permissions.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.service.security; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * This annotation tag the methods of a layer with a permission that a session 10 | * need to invoke the method. 11 | * @author javaito 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.METHOD) 15 | public @interface Permissions { 16 | Permission[] value(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/service/security/LazyPermissions.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.service.security; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * This annotation tag the methods of a layer with a permission that a session 10 | * need to invoke the method. 11 | * @author javaito 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.METHOD) 15 | public @interface LazyPermissions { 16 | LazyPermission[] value(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/proxy/ProxyTask.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.proxy; 2 | 3 | import org.hcjf.io.net.http.HttpRequest; 4 | import org.hcjf.io.net.http.HttpResponse; 5 | 6 | /** 7 | * Proxy task, this task could be one of many task into the some 8 | * http proxy instance. 9 | * @author javaito 10 | */ 11 | public abstract class ProxyTask { 12 | 13 | /** 14 | * This method execute the task. 15 | * @param request Incoming request. 16 | * @return Http response. 17 | */ 18 | public abstract HttpResponse execute(HttpRequest request); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryId.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import java.util.UUID; 4 | 5 | /** 6 | * Represents an query id. Wrapper of the UUID class. 7 | */ 8 | public final class QueryId { 9 | 10 | private final UUID id; 11 | 12 | public QueryId() { 13 | this.id = UUID.randomUUID(); 14 | } 15 | 16 | public QueryId(UUID id) { 17 | this.id = id; 18 | } 19 | 20 | /** 21 | * Get the UUID instance. 22 | * @return UUID instance. 23 | */ 24 | public UUID getId() { 25 | return id; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/locale/LocaleLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.locale; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | /** 6 | * This interface provides some methods access the locale information 7 | * based on the locale of the service session. 8 | * @author javaito 9 | */ 10 | public interface LocaleLayerInterface extends LayerInterface { 11 | 12 | /** 13 | * Translate some text to the specific language. 14 | * @param text Text to translate. 15 | * @return Returns translated text. 16 | */ 17 | public String translate(String text); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/InvokeMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class InvokeMessage extends Message { 11 | 12 | private Object[] path; 13 | 14 | public InvokeMessage() { 15 | } 16 | 17 | public InvokeMessage(UUID id) { 18 | super(id); 19 | } 20 | 21 | public Object[] getPath() { 22 | return path; 23 | } 24 | 25 | public void setPath(Object[] path) { 26 | this.path = path; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/UnlockMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class UnlockMessage extends Message { 11 | 12 | private Object[] path; 13 | 14 | public UnlockMessage() { 15 | } 16 | 17 | public UnlockMessage(UUID id) { 18 | super(id); 19 | } 20 | 21 | public Object[] getPath() { 22 | return path; 23 | } 24 | 25 | public void setPath(Object[] path) { 26 | this.path = path; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/HidePathMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class HidePathMessage extends Message { 11 | 12 | private Object[] path; 13 | 14 | public HidePathMessage() { 15 | } 16 | 17 | public HidePathMessage(UUID id) { 18 | super(id); 19 | } 20 | 21 | public Object[] getPath() { 22 | return path; 23 | } 24 | 25 | public void setPath(Object[] path) { 26 | this.path = path; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/ConsoleCommandLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.layers.distributed.DistributedLayerInterface; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public interface ConsoleCommandLayerInterface extends LayerInterface, DistributedLayerInterface { 12 | 13 | /** 14 | * Command implementation. 15 | * @param parameters Parameters to execute the command. 16 | * @return Result of the command execution. 17 | */ 18 | Object execute(List parameters); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/AdaptableLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | /** 6 | * This interface indicates that the implementation is able to adapt the arguments to force the call. 7 | */ 8 | public interface AdaptableLayer { 9 | 10 | /** 11 | * Adapt the arrays of arguments to force the layer call. 12 | * @param method Method to call. 13 | * @param args Original array of arguments. 14 | * @return New array of arguments. 15 | */ 16 | default Object[] adaptArguments(Method method, Object[] args) { 17 | return args; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/PublishPathMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class PublishPathMessage extends Message { 11 | 12 | private Object[] path; 13 | 14 | public PublishPathMessage() { 15 | } 16 | 17 | public PublishPathMessage(UUID id) { 18 | super(id); 19 | } 20 | 21 | public Object[] getPath() { 22 | return path; 23 | } 24 | 25 | public void setPath(Object[] path) { 26 | this.path = path; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/utils/bson/BsonCustomBuilderLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.utils.bson; 2 | 3 | import org.hcjf.bson.BsonDocument; 4 | import org.hcjf.layers.LayerInterface; 5 | 6 | /** 7 | * This kind of layers provides a custom way to create a instance from a bson document. 8 | * @author javaito 9 | */ 10 | public interface BsonCustomBuilderLayer

extends LayerInterface { 11 | 12 | /** 13 | * Returns a parcelable instance from a bson document. 14 | * @param document Bson document. 15 | * @return Bson parcelable instance. 16 | */ 17 | P create(BsonDocument document); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/events/RemoteEvent.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.events; 2 | 3 | /** 4 | * This class only wrap an instance of distributed event in order to 5 | * prevent the object from being sent again. 6 | * @author javaito 7 | */ 8 | public final class RemoteEvent implements Event { 9 | 10 | private final DistributedEvent event; 11 | 12 | public RemoteEvent(DistributedEvent event) { 13 | this.event = event; 14 | } 15 | 16 | public DistributedEvent getEvent() { 17 | return event; 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return event.getName(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/cache/CacheServiceConsumer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.cache; 2 | 3 | import org.hcjf.layers.Layers; 4 | import org.hcjf.service.ServiceConsumer; 5 | 6 | public class CacheServiceConsumer implements ServiceConsumer { 7 | 8 | private final String cacheImpl; 9 | 10 | public CacheServiceConsumer(String cacheImpl) { 11 | this.cacheImpl = cacheImpl; 12 | } 13 | 14 | public String getCacheImpl() { 15 | return cacheImpl; 16 | } 17 | 18 | public O get() { 19 | return (O) Layers.get(CacheLayerInterface.class, getCacheImpl()).get(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/PingFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class PingFrame extends Http2Frame { 6 | 7 | public PingFrame(Integer id, Byte flags, Integer length) { 8 | super(id, flags, length, Type.PING); 9 | } 10 | 11 | @Override 12 | protected Integer recalculateLength() { 13 | return null; 14 | } 15 | 16 | @Override 17 | protected void processPayload() { 18 | 19 | } 20 | 21 | @Override 22 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 23 | return null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/service/security/Permission.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.service.security; 2 | 3 | import org.hcjf.utils.Strings; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * This annotation tag the methods of a layer with a permission that a session 9 | * need to invoke the method. 10 | * @author javaito 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.METHOD) 14 | @Repeatable(Permissions.class) 15 | public @interface Permission { 16 | String value(); 17 | String title() default Strings.EMPTY_STRING; 18 | String description() default Strings.EMPTY_STRING; 19 | String[] tags() default {}; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/messages/NetUtils.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.messages; 2 | 3 | import java.net.DatagramSocket; 4 | import java.net.InetAddress; 5 | 6 | public class NetUtils { 7 | 8 | private static String localIp; 9 | 10 | public static synchronized String getLocalIp() { 11 | if(localIp == null) { 12 | try(final DatagramSocket socket = new DatagramSocket()){ 13 | socket.connect(InetAddress.getByName("8.8.8.8"), 10002); 14 | localIp = socket.getLocalAddress().getHostAddress(); 15 | } catch (Exception ex){} 16 | } 17 | return localIp; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/service/security/LazyPermission.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.service.security; 2 | 3 | import org.hcjf.utils.Strings; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * This annotation tag the methods of a layer with a permission that a session 9 | * need to invoke the method. 10 | * @author javaito 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.METHOD) 14 | @Repeatable(LazyPermissions.class) 15 | public @interface LazyPermission { 16 | String value(); 17 | String title() default Strings.EMPTY_STRING; 18 | String description() default Strings.EMPTY_STRING; 19 | String[] tags() default {}; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/RequestBodyDecoderLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * This class defines the interface to write the http request 9 | * body parser for each content type. 10 | * @author javaito 11 | */ 12 | public interface RequestBodyDecoderLayer extends LayerInterface { 13 | 14 | /** 15 | * Returns a map with the parameters parsed from the request body. 16 | * @param request Http request instance. 17 | * @return Map with all the parameters. 18 | */ 19 | Map decode(HttpRequest request); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/HeadersFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class HeadersFrame extends Http2Frame { 6 | 7 | public HeadersFrame(Integer id, Byte flags, Integer length) { 8 | super(id, flags, length, Type.HEADERS); 9 | } 10 | 11 | @Override 12 | protected Integer recalculateLength() { 13 | return null; 14 | } 15 | 16 | @Override 17 | protected void processPayload() { 18 | 19 | } 20 | 21 | @Override 22 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 23 | return null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/MethodResponseMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class MethodResponseMessage extends Message { 11 | 12 | private Object response; 13 | 14 | public MethodResponseMessage() { 15 | } 16 | 17 | public MethodResponseMessage(UUID id) { 18 | super(id); 19 | } 20 | 21 | public Object getResponse() { 22 | return response; 23 | } 24 | 25 | public void setResponse(Object response) { 26 | this.response = response; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/PriorityFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class PriorityFrame extends Http2Frame { 6 | 7 | public PriorityFrame(Integer id, Byte flags, Integer length) { 8 | super(id, flags, length, Type.PRIORITY); 9 | } 10 | 11 | @Override 12 | protected Integer recalculateLength() { 13 | return null; 14 | } 15 | 16 | @Override 17 | protected void processPayload() { 18 | 19 | } 20 | 21 | @Override 22 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 23 | return null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryConditional.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | 5 | public interface QueryConditional { 6 | 7 | /** 8 | * Return query instance that contains all the evaluators. 9 | * @return Query evaluation instance. 10 | */ 11 | Query getEvaluationQuery(); 12 | 13 | class ConditionalValue { 14 | 15 | private final String value; 16 | 17 | public ConditionalValue(String value) { 18 | this.value = value; 19 | } 20 | 21 | public String getValue() { 22 | return value; 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/PushPromiseFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class PushPromiseFrame extends Http2Frame { 6 | 7 | public PushPromiseFrame(Integer id, Byte flags, Integer length) { 8 | super(id, flags, length, Type.PUSH_PROMISE); 9 | } 10 | 11 | @Override 12 | protected Integer recalculateLength() { 13 | return null; 14 | } 15 | 16 | @Override 17 | protected void processPayload() { 18 | } 19 | 20 | @Override 21 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 22 | return null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/RstStreamFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class RstStreamFrame extends Http2Frame { 6 | 7 | public RstStreamFrame(Integer id, Byte flags, Integer length) { 8 | super(id, flags, length, Type.RST_STREAM); 9 | } 10 | 11 | @Override 12 | protected Integer recalculateLength() { 13 | return null; 14 | } 15 | 16 | @Override 17 | protected void processPayload() { 18 | 19 | } 20 | 21 | @Override 22 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 23 | return null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/EventMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.events.DistributedEvent; 4 | import org.hcjf.io.net.messages.Message; 5 | 6 | import java.util.UUID; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public class EventMessage extends Message { 12 | 13 | public DistributedEvent event; 14 | 15 | public EventMessage() { 16 | } 17 | 18 | public EventMessage(UUID id) { 19 | super(id); 20 | } 21 | 22 | public DistributedEvent getEvent() { 23 | return event; 24 | } 25 | 26 | public void setEvent(DistributedEvent event) { 27 | this.event = event; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/ContinuationFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class ContinuationFrame extends Http2Frame { 6 | 7 | public ContinuationFrame(Integer id, Byte flags, Integer length) { 8 | super(id, flags, length, Type.CONTINUATION); 9 | } 10 | 11 | @Override 12 | protected Integer recalculateLength() { 13 | return null; 14 | } 15 | 16 | @Override 17 | protected void processPayload() { 18 | 19 | } 20 | 21 | @Override 22 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 23 | return fixedBuffer; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryOrderField.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | 5 | /** 6 | * This class represents a order field with desc property 7 | */ 8 | public class QueryOrderField extends QueryField implements QueryOrderParameter { 9 | 10 | private final boolean desc; 11 | 12 | public QueryOrderField(Query query, String fieldPath, boolean desc) { 13 | super(query, fieldPath); 14 | this.desc = desc; 15 | } 16 | 17 | /** 18 | * Return the desc property. 19 | * @return Desc property. 20 | */ 21 | public boolean isDesc() { 22 | return desc; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/QueryFunctionLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | /** 6 | * These kind of layers are using for the query implementation to resolve 7 | * the functions specified into the each query. 8 | * @author javaito. 9 | */ 10 | public interface QueryFunctionLayerInterface extends LayerInterface { 11 | 12 | /** 13 | * Evaluates the specific function. 14 | * @param functionName Function name. 15 | * @param parameters Function's parameters. 16 | * @return Function result. 17 | */ 18 | Object evaluate(String functionName, Object... parameters); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/BusyNodeMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.cloud.impl.network.Node; 4 | import org.hcjf.io.net.messages.Message; 5 | 6 | import java.util.UUID; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public class BusyNodeMessage extends Message { 12 | 13 | private Node node; 14 | 15 | public BusyNodeMessage() { 16 | } 17 | 18 | public BusyNodeMessage(Node node) { 19 | super(UUID.randomUUID()); 20 | this.node = node; 21 | } 22 | 23 | public Node getNode() { 24 | return node; 25 | } 26 | 27 | public void setNode(Node node) { 28 | this.node = node; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/layered/LayeredResponse.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.layered; 2 | 3 | import org.hcjf.io.net.http.HttpResponse; 4 | 5 | /** 6 | * Response package for the layered contexts. 7 | * @author javaito 8 | */ 9 | public class LayeredResponse extends HttpResponse { 10 | 11 | private final Object layerResponse; 12 | 13 | public LayeredResponse(Object layerResponse) { 14 | this.layerResponse = layerResponse; 15 | } 16 | 17 | /** 18 | * Get the response object of the layer's invocation 19 | * @return Response object. 20 | */ 21 | public final Object getLayerResponse() { 22 | return layerResponse; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/TrueEvaluator.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | import org.hcjf.layers.query.Queryable; 4 | 5 | /** 6 | * This kind of evaluator is used to reduce the query. 7 | * @author javaito. 8 | * 9 | */ 10 | public final class TrueEvaluator implements Evaluator { 11 | 12 | /** 13 | * Every time return true. 14 | * @param object Object of the data collection. 15 | * @param consumer Consumer 16 | * @return Return every time true. 17 | */ 18 | @Override 19 | public boolean evaluate(Object object, Queryable.DataSource dataSource, Queryable.Consumer consumer) { 20 | return true; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/events/DistributedEvent.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.events; 2 | 3 | import org.hcjf.utils.bson.BsonParcelable; 4 | 5 | /** 6 | * @author javaito 7 | */ 8 | public interface DistributedEvent extends Event, BsonParcelable { 9 | 10 | /** 11 | * If the event is private sending only for an other replica of the same service. 12 | * @return Private value. 13 | */ 14 | default Boolean isPrivate() { 15 | return false; 16 | } 17 | 18 | /** 19 | * If the event is broadcasting then the event is sending far all the replicas. 20 | * @return Broadcasting value. 21 | */ 22 | default Boolean isBroadcasting() { 23 | return false; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/QueryAggregateFunctionLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | import java.util.Collection; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public interface QueryAggregateFunctionLayerInterface extends LayerInterface { 11 | 12 | /** 13 | * Evaluates the specific function. 14 | * @param resultSet Result set obtained for the query evaluation. 15 | * @param parameters Function's parameters. 16 | * @param alias Alias of the function 17 | * @return Function result. 18 | */ 19 | Collection evaluate(String alias, Collection resultSet, Object... parameters); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/scripting/CodeEvaluator.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.scripting; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * This interface provides a method to evaluate an script in different languages. 9 | */ 10 | public interface CodeEvaluator extends LayerInterface { 11 | 12 | /** 13 | * Evaluate the script with a set of parameter and store the result into the result object. 14 | * @param script Script to evaluate. 15 | * @param parameters Parameters object. 16 | * @return Returns a map with the result model of evaluate script. 17 | */ 18 | ExecutionResult evaluate(String script, Map parameters); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/utils/SetNullTest.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.utils; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.Map; 7 | 8 | public class SetNullTest { 9 | 10 | @Test 11 | public void test() { 12 | Map model = Introspection.createAndPut(1, "fields.integer"); 13 | model = Introspection.put(model, "lalala", "fields.string"); 14 | Integer integerValue = Introspection.resolve(model, "fields.integer"); 15 | Assert.assertEquals(integerValue, Integer.valueOf(1)); 16 | model = Introspection.put(model, null, "fields.integer"); 17 | Assert.assertNull(Introspection.resolve(model, "fields.integer")); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/SessionMetadata.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console; 2 | 3 | import org.hcjf.utils.bson.BsonParcelable; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * Session metadata model. 9 | * @author javaito 10 | */ 11 | public class SessionMetadata implements BsonParcelable { 12 | 13 | private UUID id; 14 | private String sessionName; 15 | 16 | public UUID getId() { 17 | return id; 18 | } 19 | 20 | public void setId(UUID id) { 21 | this.id = id; 22 | } 23 | 24 | public String getSessionName() { 25 | return sessionName; 26 | } 27 | 28 | public void setSessionName(String sessionName) { 29 | this.sessionName = sessionName; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/messages/LoadPluginMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | /** 6 | * This message contains the plugin file. 7 | * @author javaito 8 | */ 9 | public class LoadPluginMessage extends Message { 10 | 11 | private byte[] pluginFile; 12 | 13 | /** 14 | * Returns the plugin file 15 | * @return Plugin file. 16 | */ 17 | public byte[] getPluginFile() { 18 | return pluginFile; 19 | } 20 | 21 | /** 22 | * Set the plugin file. 23 | * @param pluginFile Plugin file. 24 | */ 25 | public void setPluginFile(byte[] pluginFile) { 26 | this.pluginFile = pluginFile; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/NodeIdentificationMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.cloud.impl.network.Node; 4 | import org.hcjf.io.net.messages.Message; 5 | 6 | import java.util.UUID; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public class NodeIdentificationMessage extends Message { 12 | 13 | private Node node; 14 | 15 | public NodeIdentificationMessage() { 16 | } 17 | 18 | public NodeIdentificationMessage(Node node) { 19 | super(UUID.randomUUID()); 20 | this.node = node; 21 | } 22 | 23 | public Node getNode() { 24 | return node; 25 | } 26 | 27 | public void setNode(Node node) { 28 | this.node = node; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/locale/DefaultLocaleLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.locale; 2 | 3 | import org.hcjf.layers.Layer; 4 | 5 | /** 6 | * This is the default implementation 7 | * @author javaito 8 | */ 9 | public class DefaultLocaleLayer extends Layer implements LocaleLayerInterface { 10 | 11 | public DefaultLocaleLayer() { 12 | } 13 | 14 | @Override 15 | public String getImplName(){ 16 | return getClass().getName(); 17 | } 18 | 19 | /** 20 | * Do nothing with the text parameter. 21 | * @param text Text to translate. 22 | * @return Return the same text. 23 | */ 24 | @Override 25 | public String translate(String text) { 26 | return text; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/messages/EncryptedMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.messages; 2 | 3 | /** 4 | * This kind of message are only a wrapper that contains the original message encrypted. 5 | * @author javaito 6 | */ 7 | public class EncryptedMessage extends Message { 8 | 9 | private byte[] encrypedData; 10 | 11 | /** 12 | * Returns the encrypted data. 13 | * @return Encrypted data. 14 | */ 15 | public byte[] getEncrypedData() { 16 | return encrypedData; 17 | } 18 | 19 | /** 20 | * Set the encrypted data. 21 | * @param encrypedData Encrypted data. 22 | */ 23 | public void setEncrypedData(byte[] encrypedData) { 24 | this.encrypedData = encrypedData; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryOrderFunction.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | 5 | import java.util.List; 6 | 7 | public class QueryOrderFunction extends QueryFunction implements QueryOrderParameter { 8 | 9 | private final boolean desc; 10 | 11 | public QueryOrderFunction(Query query, String originalFunction, String functionName, List parameters, boolean desc) { 12 | super(query, originalFunction, functionName, parameters); 13 | this.desc = desc; 14 | } 15 | 16 | /** 17 | * Return the desc property. 18 | * @return Desc property. 19 | */ 20 | public boolean isDesc() { 21 | return desc; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/DefaultLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * This annotation is to identify if some implementation is the default 10 | * implementation to resolve a set of interfaces. 11 | * @author javaito 12 | */ 13 | @Target(ElementType.TYPE) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface DefaultLayer { 16 | 17 | /** 18 | * Contains all the interfaces that the annotated class is a default implementation. 19 | * @return Set of interfaces. 20 | */ 21 | Class[] value(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/errors/TaggedException.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.errors; 2 | 3 | import org.hcjf.properties.SystemProperties; 4 | import org.hcjf.utils.Strings; 5 | 6 | public class TaggedException extends RuntimeException { 7 | 8 | public TaggedException(String tag, String message, Object... params) { 9 | this(tag, message, null, params); 10 | } 11 | 12 | public TaggedException(String tag, String message, Throwable cause, Object... params) { 13 | super(Strings.createTaggedMessage(String.format(message, params), tag, getNodeNameTag()), cause); 14 | } 15 | 16 | protected static String getNodeNameTag() { 17 | return SystemProperties.get(SystemProperties.Cloud.Orchestrator.ThisNode.NAME).toUpperCase(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/scripting/PythonCodeEvaluator.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.scripting; 2 | 3 | import org.hcjf.layers.Layer; 4 | 5 | import java.util.Map; 6 | 7 | public class PythonCodeEvaluator extends Layer implements CodeEvaluator { 8 | 9 | /** 10 | * Evaluate the script with a set of parameter and store the result into the result object. 11 | * @param script Script to evaluate. 12 | * @param parameters Parameters object. 13 | * @return Returns a map with the result model of evaluate script. 14 | */ 15 | @Override 16 | public ExecutionResult evaluate(String script, Map parameters) { 17 | 18 | // ServiceSession.getCurrentIdentity(). 19 | 20 | return null; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/Evaluator.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | import org.hcjf.layers.query.Queryable; 4 | 5 | /** 6 | * @author javaito 7 | * 8 | */ 9 | public interface Evaluator { 10 | 11 | /** 12 | * This method must be implemented for each particular implementation 13 | * to evaluate some details about instances of the data collection. 14 | * @param object Object of the data collection. 15 | * @param dataSource Data source. 16 | * @param consumer Consumer. 17 | * @return Return true if the object must be part of the result add or false in the 18 | * other ways. 19 | */ 20 | boolean evaluate(Object object, Queryable.DataSource dataSource, Queryable.Consumer consumer); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/proxy/HttpProxyRule.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.proxy; 2 | 3 | import org.hcjf.io.net.http.HttpRequest; 4 | 5 | /** 6 | * This class analyze the requests and return a set of redirection 7 | * task to be executed for the http proxy. 8 | * @author javaito 9 | */ 10 | public abstract class HttpProxyRule { 11 | 12 | /** 13 | * Checks whether the request meets the conditions of the rule. 14 | * @param request Incoming request. 15 | * @return True if the request meets the conditions. 16 | */ 17 | public abstract boolean evaluate(HttpRequest request); 18 | 19 | /** 20 | * Return the proxy task of the rule. 21 | * @return Proxy task. 22 | */ 23 | public abstract ProxyTask getTask(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/resources/Resourceable.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.resources; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | import java.util.Set; 6 | 7 | /** 8 | * This interface make able that the layer implementation be published as system resource, 9 | * indexed by an specific name with all the properties needed to consume the resource. 10 | * @author javaito. 11 | */ 12 | public interface Resourceable { 13 | 14 | /** 15 | * The implementation of this method must create an instance of resource for each 16 | * layer interface as parameter. 17 | * @param layerInterface Layer interface 18 | * @return Returns the 19 | */ 20 | public Set createResource(Class layerInterface); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/utils/NamedUuidTest.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.utils; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | /** 7 | * @author javaito 8 | */ 9 | public class NamedUuidTest { 10 | 11 | @Test 12 | public void testNamedUudi() { 13 | String name = getClass().getName(); 14 | Integer hashCode = name.hashCode(); 15 | NamedUuid.registerName(name); 16 | 17 | NamedUuid namedUuid = NamedUuid.create(name); 18 | Assert.assertEquals(namedUuid.getHash(), hashCode); 19 | Assert.assertEquals(NamedUuid.getName(namedUuid.getId()), name); 20 | 21 | NamedUuid namedUuidFromUuid = NamedUuid.create(namedUuid.getId()); 22 | Assert.assertEquals(namedUuidFromUuid.getHash(), hashCode); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/counter/Counter.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.counter; 2 | 3 | /** 4 | * Distributed atomic counter. 5 | * @author javaito 6 | */ 7 | public interface Counter { 8 | 9 | /** 10 | * This method return the last number and add one unit to the counter 11 | * in one atomic operation over the cloud. 12 | * @return Return the last value of the counter before increase. 13 | */ 14 | public Long getAndAdd(); 15 | 16 | /** 17 | * This method return the last number and add the counter 18 | * in one atomic operation over the cloud. 19 | * @param offset Offset to increment the counter value. 20 | * @return Return the last value of the counter before increase. 21 | */ 22 | public Long getAndAdd(Long offset); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/LockMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class LockMessage extends Message { 11 | 12 | private Object[] path; 13 | private Long nanos; 14 | 15 | public LockMessage() { 16 | } 17 | 18 | public LockMessage(UUID id) { 19 | super(id); 20 | } 21 | 22 | public Object[] getPath() { 23 | return path; 24 | } 25 | 26 | public void setPath(Object[] path) { 27 | this.path = path; 28 | } 29 | 30 | public Long getNanos() { 31 | return nanos; 32 | } 33 | 34 | public void setNanos(Long nanos) { 35 | this.nanos = nanos; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/names/NamingConsumer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.names; 2 | 3 | import org.hcjf.service.ServiceConsumer; 4 | 5 | /** 6 | * Naming service consumer base class. 7 | * @author javaito 8 | */ 9 | public abstract class NamingConsumer implements ServiceConsumer { 10 | 11 | private final String name; 12 | 13 | public NamingConsumer(String name) { 14 | this.name = name; 15 | } 16 | 17 | /** 18 | * Return the name of the consumer. 19 | * @return Name of the consumer. 20 | */ 21 | public final String getName() { 22 | return name; 23 | } 24 | 25 | /** 26 | * Normalize the specific value. 27 | * @param value Value to normalize. 28 | * @return Normalized value. 29 | */ 30 | public abstract String normalize(String value); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/messages/EvaluateQueryableMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | import org.hcjf.layers.query.Queryable; 5 | 6 | /** 7 | * This message contains a queryable to execute. 8 | * @author javaito 9 | */ 10 | public class EvaluateQueryableMessage extends Message { 11 | 12 | private Queryable queryable; 13 | 14 | /** 15 | * Returns the queryable instance. 16 | * @return Queryable. 17 | */ 18 | public Queryable getQueryable() { 19 | return queryable; 20 | } 21 | 22 | /** 23 | * Set the queryable instance. 24 | * @param queryable Queryable instance. 25 | */ 26 | public void setQueryable(Queryable queryable) { 27 | this.queryable = queryable; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/messages/LoginMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * This message contains the login information. 9 | * @author javaito 10 | */ 11 | public class LoginMessage extends Message { 12 | 13 | private Map parameters; 14 | 15 | /** 16 | * Returns the login parameters. 17 | * @return Login parameters. 18 | */ 19 | public Map getParameters() { 20 | return parameters; 21 | } 22 | 23 | /** 24 | * Set the login parameters. 25 | * @param parameters Login parameters. 26 | */ 27 | public void setParameters(Map parameters) { 28 | this.parameters = parameters; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/GetIndexQueryFunctionLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.layers.query.Enlarged; 4 | import java.util.Collection; 5 | 6 | public class GetIndexQueryFunctionLayer extends BaseQueryAggregateFunctionLayer { 7 | 8 | private static final String NAME = "getIndex"; 9 | 10 | public GetIndexQueryFunctionLayer() { 11 | super(NAME); 12 | } 13 | 14 | @Override 15 | public Collection evaluate(String alias, Collection resultSet, Object... parameters) { 16 | Collection result = resultSet; 17 | int countValue = 0; 18 | for (Object row : resultSet) { 19 | countValue++; 20 | ((Enlarged) row).put(alias, countValue); 21 | } 22 | 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/WindowsUpdateFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class WindowsUpdateFrame extends Http2Frame { 6 | 7 | private Integer windowsSize; 8 | 9 | public WindowsUpdateFrame(Integer id, Byte flags, Integer length) { 10 | super(id, flags, length, Type.WINDOW_UPDATE); 11 | } 12 | 13 | @Override 14 | protected Integer recalculateLength() { 15 | return getLength(); 16 | } 17 | 18 | @Override 19 | protected void processPayload() { 20 | windowsSize = getPayload().getInt(); 21 | } 22 | 23 | @Override 24 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 25 | fixedBuffer.putInt(windowsSize); 26 | return fixedBuffer; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/org/hcjf/examples/salary/SaludCalculator.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.examples.salary; 2 | 3 | import org.hcjf.layers.Layer; 4 | import org.hcjf.utils.Introspection; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | public class SaludCalculator extends Layer implements ItemCalculator { 10 | @Override 11 | public Map calculate(Map salary, String itemName) { 12 | Double rawSalary = ((Number) Introspection.resolve(salary, "rawSalary")).doubleValue(); 13 | Double value = rawSalary * 0.07; 14 | Double totalSalary = ((Number) Introspection.resolve(salary, "totalSalary")).doubleValue(); 15 | List> items = Introspection.resolve("items"); 16 | items.add(Map.of("name", "salud", "value", value)); 17 | return salary; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/service/ServiceThreadGroup.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.service; 2 | 3 | /** 4 | * This class is a singleton and all the service thread 5 | * run over the unique instance of this class as a group. 6 | * @author javaito 7 | * 8 | */ 9 | public final class ServiceThreadGroup extends ThreadGroup { 10 | 11 | private static final String NAME = "ServiceThreadGroup"; 12 | private static final ServiceThreadGroup instance; 13 | 14 | static { 15 | instance = new ServiceThreadGroup(); 16 | } 17 | 18 | private ServiceThreadGroup() { 19 | super(NAME); 20 | } 21 | 22 | /** 23 | * Retur the unique instance of this class. 24 | * @return Unique instance of the group. 25 | */ 26 | public static ServiceThreadGroup getInstance() { 27 | return instance; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/Joinable.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query; 2 | 3 | /** 4 | * @author javaito 5 | * 6 | */ 7 | public interface Joinable { 8 | 9 | /** 10 | * Return the value that corresponds to the specific field name. 11 | * @param fieldName Field name. 12 | * @return Field value. 13 | */ 14 | Object get(String fieldName); 15 | 16 | /** 17 | * Join the data of this joinable instance with the data of the 18 | * joinable parameter. 19 | * @param leftResource Name of the left resource of the join. 20 | * @param rightResource Name of the right resource of the join. 21 | * @param joinable Joinable parameter. 22 | * @return Return the current joinable instance. 23 | */ 24 | Joinable join(String leftResource, String rightResource, Joinable joinable); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/ReadRowsLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.layers.query.JoinableMap; 5 | import org.hcjf.layers.query.Queryable; 6 | 7 | import java.util.Collection; 8 | 9 | /** 10 | * @author javaito 11 | */ 12 | public interface ReadRowsLayerInterface extends LayerInterface { 13 | 14 | /** 15 | * This method implements the read operation using the filters 16 | * specified in the query and return a collection of maps. 17 | * @param queryable Instance that contains all the information to evaluate a query. 18 | * @return Return the list with the instances founded. 19 | */ 20 | default Collection readRows(Queryable queryable) { 21 | throw new UnsupportedOperationException(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/SignalMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class SignalMessage extends Message { 11 | 12 | private String lockName; 13 | private String conditionName; 14 | 15 | public SignalMessage() { 16 | } 17 | 18 | public SignalMessage(UUID id) { 19 | super(id); 20 | } 21 | 22 | public String getLockName() { 23 | return lockName; 24 | } 25 | 26 | public void setLockName(String lockName) { 27 | this.lockName = lockName; 28 | } 29 | 30 | public String getConditionName() { 31 | return conditionName; 32 | } 33 | 34 | public void setConditionName(String conditionName) { 35 | this.conditionName = conditionName; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/SignalAllMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class SignalAllMessage extends Message { 11 | 12 | private String lockName; 13 | private String conditionName; 14 | 15 | public SignalAllMessage() { 16 | } 17 | 18 | public SignalAllMessage(UUID id) { 19 | super(id); 20 | } 21 | 22 | public String getLockName() { 23 | return lockName; 24 | } 25 | 26 | public void setLockName(String lockName) { 27 | this.lockName = lockName; 28 | } 29 | 30 | public String getConditionName() { 31 | return conditionName; 32 | } 33 | 34 | public void setConditionName(String conditionName) { 35 | this.conditionName = conditionName; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/References.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * This interface provides all the methods to implements 7 | * crud references. 8 | * @author javaito 9 | */ 10 | public interface References { 11 | 12 | /** 13 | * Returns the instance of the reference indexed by specific name. 14 | * @param referenceName Reference name. 15 | * @param Expected reference class. 16 | * @return Reference instance. 17 | */ 18 | O getReference(String referenceName); 19 | 20 | /** 21 | * Returns a collection of reference instances indexed by the specific name. 22 | * @param referenceName Reference name. 23 | * @param Expected reference class. 24 | * @return Reference instances. 25 | */ 26 | Collection getReferenceCollection(String referenceName); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/log/debug/Agent.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.log.debug; 2 | 3 | /** 4 | * This class represents an agent that collect and store data from different 5 | * points of the platform in order to monitoring and debug the instance status 6 | * @author javaito 7 | */ 8 | public class Agent { 9 | 10 | private final String packageName; 11 | private final String name; 12 | 13 | public Agent(String name, String packageName) { 14 | this.packageName = packageName; 15 | this.name = name; 16 | } 17 | 18 | /** 19 | * Returns the package name of the agent. 20 | * @return Package name of the agent. 21 | */ 22 | public final String getPackageName() { 23 | return packageName; 24 | } 25 | 26 | /** 27 | * Returns the name if the agent. 28 | * @return Name of the agent. 29 | */ 30 | public final String getName() { 31 | return name; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/IdentifiableLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud; 2 | 3 | import org.hcjf.utils.NamedUuid; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * This interface identify the layers with identifiable resources. 9 | * @author javaito 10 | */ 11 | public interface IdentifiableLayerInterface extends ReadLayerInterface { 12 | 13 | /** 14 | * Reads an instance of the resource from the data source using a uuid type 5 instance 15 | * @param uuid UUID instance. 16 | * @return Returns the resource instance. 17 | */ 18 | default O read(UUID uuid) { 19 | return read((Object)uuid); 20 | } 21 | 22 | /** 23 | * Creates a named uuid type 5 with the implementation name of the layer. 24 | * @return New instance of the uuid. 25 | */ 26 | default UUID createId() { 27 | return NamedUuid.create(getImplName()).getId(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/command/ResourceCommandLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud.command; 2 | 3 | import org.hcjf.layers.Layer; 4 | 5 | /** 6 | * Utility class to simplify implementation of a resource command.
7 | * Layer name is built using Resource::command.
8 | * Subclasses should call the parent constructor with the associated resource name and override 9 | * getCommandName to return the command name. 10 | */ 11 | public abstract class ResourceCommandLayer extends Layer implements ResourceCommandLayerInterface { 12 | 13 | private String resourceName; 14 | 15 | public ResourceCommandLayer(String resourceName) { 16 | this.resourceName = resourceName; 17 | } 18 | 19 | protected abstract String getCommandName(); 20 | 21 | @Override 22 | public String getImplName() { 23 | return String.format("%s::%s", resourceName, getCommandName()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryReturnField.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | 5 | /** 6 | * This kind of component represent the fields to be returned into the query. 7 | */ 8 | public class QueryReturnField extends QueryField implements QueryReturnParameter { 9 | 10 | private final String alias; 11 | 12 | public QueryReturnField(Query query, String fieldPath) { 13 | this(query, fieldPath, fieldPath); 14 | } 15 | 16 | public QueryReturnField(Query query, String fieldPath, String alias) { 17 | super(query, fieldPath); 18 | if(alias == null) { 19 | this.alias = fieldPath; 20 | } else { 21 | this.alias = alias; 22 | } 23 | } 24 | 25 | /** 26 | * Return the field alias, can be null. 27 | * @return Field alias. 28 | */ 29 | public String getAlias() { 30 | return alias; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/cache/CacheLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.cache; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.service.ServiceConsumer; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * This interface defines a signature for a cache layer. 10 | * @param Kind of object that the cache layer use. 11 | */ 12 | public interface CacheLayerInterface extends LayerInterface, ServiceConsumer { 13 | 14 | /** 15 | * This method invalidate the values into cache and restore its using the datasource associated to the cache. 16 | */ 17 | void invalidate(); 18 | 19 | /** 20 | * Returns the timeout value, this value indicates the time that the cache is valid. 21 | * @return Timeout value. 22 | */ 23 | Long timout(); 24 | 25 | /** 26 | * This method returns a current values of the cache. 27 | * @return Current value of the cache. 28 | */ 29 | O get(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/CreateLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | 5 | import java.util.Collection; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public interface CreateLayerInterface extends LayerInterface { 11 | 12 | /** 13 | * This method implements the creation of the resource. 14 | * @param object Object to represents an instance of the resource. 15 | * @return The instance of the resource. 16 | */ 17 | default O create(O object) { 18 | throw new UnsupportedOperationException(); 19 | } 20 | 21 | /** 22 | * This method implements the creation of a list of resources. 23 | * @param objects List of Objects to represents the instances of the resources. 24 | * @return The list of instances of the resources. 25 | */ 26 | default Collection create(Collection objects) { 27 | throw new UnsupportedOperationException(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/Groupable.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * This interface represents all object capable of being grouped 7 | * @author javaito. 8 | * 9 | */ 10 | public interface Groupable { 11 | 12 | /** 13 | * Return the value that corresponds to the specific field name. 14 | * @param fieldName Field name. 15 | * @return Field value. 16 | */ 17 | Object get(String fieldName); 18 | 19 | /** 20 | * Returns all the labels into the groupable instance. 21 | * @return Set with all the labels. 22 | */ 23 | Set keySet(); 24 | 25 | /** 26 | * Group this instance with the parameter instance. 27 | * @param groupable Other instance to group. 28 | * @return Return this instance grouped. 29 | */ 30 | Groupable group(Groupable groupable); 31 | 32 | /** 33 | * Remove all the elements of the groupable object. 34 | */ 35 | void clear(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/log/debug/Agents.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.log.debug; 2 | 3 | import javax.management.MBeanServer; 4 | import javax.management.ObjectName; 5 | import java.lang.management.ManagementFactory; 6 | 7 | /** 8 | * Class with some static useful methods to register and search information 9 | * about agents. 10 | * @author javaito 11 | */ 12 | public class Agents { 13 | 14 | public static final String OBJECT_NAME_TEMPLATE = "%s:type=%s"; 15 | 16 | /** 17 | * Registers an agent into the MBean server of the instance of jvm. 18 | * @param agent Agent to register. 19 | */ 20 | public static void register(Agent agent) { 21 | try { 22 | MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 23 | ObjectName name = new ObjectName(String.format(OBJECT_NAME_TEMPLATE, 24 | agent.getPackageName(), agent.getName())); 25 | mbs.registerMBean(agent, name); 26 | } catch (Exception ex){} 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryBsonBuilderLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.bson.BsonDocument; 4 | import org.hcjf.layers.Layer; 5 | import org.hcjf.layers.query.Query; 6 | import org.hcjf.utils.bson.BsonCustomBuilderLayer; 7 | 8 | /** 9 | * This inner class implements the custom method to create a query instance from a bson document. 10 | */ 11 | public class QueryBsonBuilderLayer extends Layer implements BsonCustomBuilderLayer { 12 | 13 | public QueryBsonBuilderLayer() { 14 | super(Query.class.getName()); 15 | } 16 | 17 | /** 18 | * This implementation required that the document contains a field called '__query__' to create the query instance. 19 | * @param document Bson document. 20 | * @return Returns a query instance. 21 | */ 22 | @Override 23 | public Query create(BsonDocument document) { 24 | return Query.compile(document.get(Query.QUERY_BSON_FIELD_NAME).getAsString()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /.travis/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | ossrh 8 | ${env.SONATYPE_USERNAME} 9 | ${env.SONATYPE_PASSWORD} 10 | 11 | 12 | 13 | 14 | ossrh 15 | 16 | true 17 | 18 | 19 | ${env.GPG_KEY_NAME} 20 | ${env.GPG_EXECUTABLE} 21 | ${env.GPG_PASSPHRASE} 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/EvalExpressionAggregateFunctionLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.layers.query.Enlarged; 4 | 5 | import java.util.Collection; 6 | 7 | public class EvalExpressionAggregateFunctionLayer extends BaseQueryAggregateFunctionLayer implements NumberSetFunction { 8 | 9 | private static final String NAME = "aggregateEvalExpression"; 10 | 11 | public EvalExpressionAggregateFunctionLayer() { 12 | super(NAME); 13 | } 14 | 15 | @Override 16 | public Collection evaluate(String alias, Collection resultSet, Object... parameters) { 17 | Object[] resolvedParameters = new Object[parameters.length]; 18 | for(Object row : resultSet) { 19 | for (int i = 0; i < parameters.length; i++) { 20 | resolvedParameters[i] = resolveValue(row, parameters[i]); 21 | } 22 | ((Enlarged)row).put(alias, evalExpression(resolvedParameters)); 23 | } 24 | return resultSet; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/utils/MatrixBsonBuilderLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.utils; 2 | 3 | import org.hcjf.bson.BsonArray; 4 | import org.hcjf.bson.BsonDocument; 5 | import org.hcjf.layers.Layer; 6 | import org.hcjf.utils.bson.BsonCustomBuilderLayer; 7 | 8 | public class MatrixBsonBuilderLayer extends Layer implements BsonCustomBuilderLayer { 9 | 10 | public MatrixBsonBuilderLayer() { 11 | super(Matrix.class.getName()); 12 | } 13 | 14 | /** 15 | * Returns a parcelable instance from a bson document. 16 | * 17 | * @param document Bson document. 18 | * @return Bson parcelable instance. 19 | */ 20 | @Override 21 | public Matrix create(BsonDocument document) { 22 | Integer rows = document.get(Matrix.Fields.ROWS).getAsInteger(); 23 | Integer cols = document.get(Matrix.Fields.COLS).getAsInteger(); 24 | BsonArray values = document.get(Matrix.Fields.DATA).getAsArray(); 25 | return new Matrix(rows, cols, values.toList().toArray(new Number[]{})); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/ContextAggregateFunction.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import java.util.Collection; 4 | import java.util.Map; 5 | 6 | public class ContextAggregateFunction extends BaseQueryAggregateFunctionLayer { 7 | 8 | private static final String NAME = "aggregateContext"; 9 | 10 | public ContextAggregateFunction() { 11 | super(NAME); 12 | } 13 | 14 | /** 15 | * Evaluates the specific function. 16 | * @param alias Alias of the function 17 | * @param resultSet Result set obtained for the query evaluation. 18 | * @param parameters Function's parameters. 19 | * @return Function result. 20 | */ 21 | @Override 22 | public Collection evaluate(String alias, Collection resultSet, Object... parameters) { 23 | Object value; 24 | for (Object row : resultSet) { 25 | value = resolveValue(row, parameters[0]); 26 | ((Map)row).put(alias, value); 27 | } 28 | return resultSet; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/errors/HCJFRuntimeException.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.errors; 2 | 3 | import org.hcjf.properties.SystemProperties; 4 | 5 | public class HCJFRuntimeException extends TaggedException { 6 | 7 | private static final String EXCEPTION_TAG = "SYSTEM_EX"; 8 | private static final String ERROR_TAG = "SYSTEM_ERR"; 9 | 10 | public HCJFRuntimeException(String message, Object... params) { 11 | this(message, null, params); 12 | } 13 | 14 | public HCJFRuntimeException(String message, Throwable cause, Object... params) { 15 | super(getTag(cause), message, cause, params); 16 | } 17 | 18 | protected static String getTag(Throwable cause) { 19 | String tag = SystemProperties.get(SystemProperties.HCJF_DEFAULT_EXCEPTION_MESSAGE_TAG); 20 | if(cause != null) { 21 | if(cause instanceof Error) { 22 | tag = ERROR_TAG; 23 | } else if(cause instanceof Exception) { 24 | tag = EXCEPTION_TAG; 25 | } 26 | } 27 | return tag; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/objects/DistributedLock.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.objects; 2 | 3 | /** 4 | * @author javaito 5 | */ 6 | public class DistributedLock{ 7 | 8 | private Long timestamp; 9 | private Long nanos; 10 | private Status status; 11 | 12 | public DistributedLock() { 13 | status = Status.UNLOCKED; 14 | this.timestamp = Long.MAX_VALUE; 15 | this.nanos = Long.MAX_VALUE; 16 | } 17 | 18 | public final Status getStatus() { 19 | return status; 20 | } 21 | 22 | public final void setStatus(Status status) { 23 | this.timestamp = System.currentTimeMillis(); 24 | this.status = status; 25 | this.nanos = System.nanoTime(); 26 | } 27 | 28 | public final Long getTimestamp() { 29 | return timestamp; 30 | } 31 | 32 | public final Long getNanos() { 33 | return nanos; 34 | } 35 | 36 | public enum Status { 37 | 38 | UNLOCKED, 39 | 40 | LOCKING, 41 | 42 | LOCKED, 43 | 44 | WAITING 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/proxy/TcpProxySession.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.proxy; 2 | 3 | import org.hcjf.io.net.NetServiceConsumer; 4 | import org.hcjf.io.net.NetSession; 5 | 6 | import java.util.UUID; 7 | 8 | public class TcpProxySession extends NetSession { 9 | 10 | private final String host; 11 | private final Boolean client; 12 | private final Boolean main; 13 | 14 | public TcpProxySession(UUID id, NetServiceConsumer consumer, String host) { 15 | super(id, consumer); 16 | this.host = host; 17 | this.client = false; 18 | this.main = false; 19 | } 20 | 21 | public TcpProxySession(UUID id, NetServiceConsumer consumer, String host, Boolean client, Boolean main) { 22 | super(id, consumer); 23 | this.host = host; 24 | this.client = client; 25 | this.main = main; 26 | } 27 | 28 | public String getHost() { 29 | return host; 30 | } 31 | 32 | public Boolean getClient() { 33 | return client; 34 | } 35 | 36 | public Boolean getMain() { 37 | return main; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://img.shields.io/travis/javaito/HolandaCatalinaFw.svg) 2 | ![](https://img.shields.io/github/license/javaito/HolandaCatalinaFw.svg) 3 | ![](https://img.shields.io/github/release/javaito/HolandaCatalinaFw.svg) 4 | ![Maven Central](https://img.shields.io/maven-central/v/com.github.javaito/hcjf.svg) 5 | ![](https://img.shields.io/github/forks/javaito/HolandaCatalinaFw.svg?style=social&label=Fork) 6 | ![](https://img.shields.io/github/stars/javaito/HolandaCatalinaFw.svg?style=social&label=Star) 7 | ![](https://img.shields.io/github/watchers/javaito/HolandaCatalinaFw.svg?style=social&label=Watch) 8 | 9 | # Holanda Catalina 10 | 11 | Holanda Catalina is a powerful framework to create your own solution based on a micro-services architecture, without realizing that you are doing it. ;) 12 | 13 | ## Table of Contents 14 | - [Introduction](introduction.md) 15 | - [Getting started](getting-started.md) 16 | - [My first service](my-first-service.md) 17 | - [Very good things!](very-good-things.md) 18 | 19 | ## Acknowledgements 20 | 21 | - [Microservice Architecture](http://microservices.io/index.html) 22 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/objects/DistributedLeaf.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.objects; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public abstract class DistributedLeaf implements DistributedObject { 11 | 12 | private final Object key; 13 | private Long lastUpdate; 14 | private final Set nodes; 15 | private final Set serviceEndPoints; 16 | 17 | public DistributedLeaf(Object key) { 18 | this.key = key; 19 | this.nodes = new HashSet<>(); 20 | this.serviceEndPoints = new HashSet<>(); 21 | } 22 | 23 | @Override 24 | public Object getKey() { 25 | return key; 26 | } 27 | 28 | public final Long getLastUpdate() { 29 | return lastUpdate; 30 | } 31 | 32 | public final void setLastUpdate(Long lastUpdate) { 33 | this.lastUpdate = lastUpdate; 34 | } 35 | 36 | public Set getNodes() { 37 | return nodes; 38 | } 39 | 40 | public Set getServiceEndPoints() { 41 | return serviceEndPoints; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/DeleteLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.layers.query.Queryable; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public interface DeleteLayerInterface extends LayerInterface { 12 | 13 | /** 14 | * This method implements the delete operation over the resource. 15 | * @param id Id of the instance that gonna be deleted. 16 | * @return Instance of the resource that was deleted. 17 | */ 18 | default O delete(Object id) { 19 | throw new UnsupportedOperationException(); 20 | } 21 | 22 | /** 23 | * This method implements the delete operation over a add of the instances. 24 | * This instances are selected using the query like a match. 25 | * @param queryable Instance that contains all the information to evaluate a query. 26 | * @return Return the instances deleted. 27 | */ 28 | default Collection delete(Queryable queryable) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/network/CloudSession.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.network; 2 | 3 | import org.hcjf.cloud.impl.messages.AckMessage; 4 | import org.hcjf.io.net.NetServiceConsumer; 5 | import org.hcjf.io.net.NetSession; 6 | 7 | import java.util.UUID; 8 | 9 | /** 10 | * @author javaito. 11 | */ 12 | public class CloudSession extends NetSession { 13 | 14 | private AckMessage ackMessage; 15 | private Node node; 16 | 17 | public CloudSession(NetServiceConsumer consumer) { 18 | super(UUID.randomUUID(), consumer); 19 | } 20 | 21 | protected CloudSession(CloudSession cloudSession) { 22 | super(cloudSession); 23 | this.ackMessage = cloudSession.ackMessage; 24 | this.node = cloudSession.node; 25 | } 26 | 27 | public AckMessage getAckMessage() { 28 | return ackMessage; 29 | } 30 | 31 | public void setAckMessage(AckMessage ackMessage) { 32 | this.ackMessage = ackMessage; 33 | } 34 | 35 | public Node getNode() { 36 | return node; 37 | } 38 | 39 | public void setNode(Node node) { 40 | this.node = node; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/PublishLayerMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class PublishLayerMessage extends Message { 11 | 12 | private Object[] path; 13 | private String regex; 14 | private UUID nodeId; 15 | private UUID serviceEndPointId; 16 | 17 | public PublishLayerMessage() { 18 | } 19 | 20 | public PublishLayerMessage(UUID id) { 21 | super(id); 22 | } 23 | 24 | public Object[] getPath() { 25 | return path; 26 | } 27 | 28 | public void setPath(Object[] path) { 29 | this.path = path; 30 | } 31 | 32 | public String getRegex() { 33 | return regex; 34 | } 35 | 36 | public void setRegex(String regex) { 37 | this.regex = regex; 38 | } 39 | 40 | public UUID getServiceEndPointId() { 41 | return serviceEndPointId; 42 | } 43 | 44 | public void setServiceEndPointId(UUID serviceEndPointId) { 45 | this.serviceEndPointId = serviceEndPointId; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/NetClient.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net; 2 | 3 | /** 4 | * This class is a kind of net consumer that represent 5 | * a client for the ip connections. 6 | * @author javaito 7 | */ 8 | public abstract class NetClient extends NetServiceConsumer { 9 | 10 | private String host; 11 | 12 | public NetClient(String host, Integer port, NetService.TransportLayerProtocol protocol) { 13 | super(port, protocol); 14 | this.host = host; 15 | } 16 | 17 | /** 18 | * Put the client on the net service implementation 19 | */ 20 | protected void connect() { 21 | NetService.getInstance().registerConsumer(this); 22 | } 23 | 24 | /** 25 | * Returns the host where it will connect the client 26 | * @return Remote host. 27 | */ 28 | public String getHost() { 29 | return host; 30 | } 31 | 32 | /** 33 | * This method return the object that represent the 34 | * client's session. 35 | * @return Client's session. 36 | */ 37 | public abstract S getSession(); 38 | 39 | protected void onConnectFail() {} 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/cache/CloudCacheStrategy.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.cache; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * This interface define the cache strategy implementations. 7 | * @author javaito 8 | */ 9 | public interface CloudCacheStrategy { 10 | 11 | /** 12 | * Init the strategy for a particular instance of cache. 13 | * @param cacheInstance Instance of cache. 14 | */ 15 | void init(CloudCache cacheInstance); 16 | 17 | /** 18 | * This method is called when some object was removed to the cache instance. 19 | * @param id Id removed to the cache instance. 20 | */ 21 | void onRemove(Object id); 22 | 23 | /** 24 | * This method is called when some object was added to the cache instance. 25 | * @param id Id added into the cache instance. 26 | * @param value Value added into cache. 27 | */ 28 | void onAdd(Object id, Object value); 29 | 30 | /** 31 | * This method must evaluate the specific strategy and return all the 32 | * ids that will be removed of the cache implementation. 33 | * @return Collection of the ids that will be removed. 34 | */ 35 | Set applyStrategy(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/events/EventListener.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.events; 2 | 3 | import org.hcjf.service.ServiceConsumer; 4 | 5 | import java.lang.reflect.ParameterizedType; 6 | import java.lang.reflect.Type; 7 | 8 | /** 9 | * This class resolve the interface to receive events of the instance. 10 | * @author javaito 11 | */ 12 | public interface EventListener extends ServiceConsumer { 13 | 14 | /** 15 | * When a event is received. 16 | * @param event Received event. 17 | */ 18 | void onEventReceived(E event); 19 | 20 | /** 21 | * Return the implementation type of the event listener. 22 | * @return Implementation type. 23 | */ 24 | default Class getEventType() { 25 | Type[] superInterfaces = getClass().getGenericInterfaces(); 26 | int i = 0; 27 | Type superInterface; 28 | do { 29 | superInterface = superInterfaces[i++]; 30 | } while(!(superInterface instanceof ParameterizedType && 31 | ((ParameterizedType)superInterface).getRawType().equals(EventListener.class))); 32 | return (Class) ((ParameterizedType)superInterface).getActualTypeArguments()[0]; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/MethodInvokeMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.List; 6 | import java.util.UUID; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public class MethodInvokeMessage extends Message { 12 | 13 | private String methodName; 14 | private List parameterTypes; 15 | private List parameters; 16 | 17 | public MethodInvokeMessage() { 18 | } 19 | 20 | public MethodInvokeMessage(UUID id) { 21 | super(id); 22 | } 23 | 24 | public String getMethodName() { 25 | return methodName; 26 | } 27 | 28 | public void setMethodName(String methodName) { 29 | this.methodName = methodName; 30 | } 31 | 32 | public List getParameterTypes() { 33 | return parameterTypes; 34 | } 35 | 36 | public void setParameterTypes(List parameterTypes) { 37 | this.parameterTypes = parameterTypes; 38 | } 39 | 40 | public List getParameters() { 41 | return parameters; 42 | } 43 | 44 | public void setParameters(List parameters) { 45 | this.parameters = parameters; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryDynamicResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | 5 | public class QueryDynamicResource extends QueryResource { 6 | 7 | private static final String TO_STRING_PATTERN = "(%s) as %s"; 8 | private static final String TO_STRING_WITH_PATH_PATTERN = "(%s).%s as %s"; 9 | 10 | private final Query query; 11 | private final String path; 12 | 13 | public QueryDynamicResource(String resourceName, Query query) { 14 | this(resourceName, query, null); 15 | } 16 | 17 | public QueryDynamicResource(String resourceName, Query query, String path) { 18 | super(resourceName); 19 | this.query = query; 20 | this.path = path; 21 | } 22 | 23 | public Query getQuery() { 24 | return query; 25 | } 26 | 27 | public String getPath() { 28 | return path; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return path == null ? 34 | String.format(TO_STRING_PATTERN, getQuery().toString(), super.toString()) : 35 | String.format(TO_STRING_WITH_PATH_PATTERN, getQuery().toString(), getPath(), super.toString()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/messages/ExecuteMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * This message contains the command information. 9 | * @author javaito 10 | */ 11 | public class ExecuteMessage extends Message { 12 | 13 | private String commandName; 14 | private List parameters; 15 | 16 | /** 17 | * Returns the command name. 18 | * @return Command name. 19 | */ 20 | public String getCommandName() { 21 | return commandName; 22 | } 23 | 24 | /** 25 | * Set the command name. 26 | * @param commandName Command name. 27 | */ 28 | public void setCommandName(String commandName) { 29 | this.commandName = commandName; 30 | } 31 | 32 | /** 33 | * Returns the command parameters. 34 | * @return Command parameters. 35 | */ 36 | public List getParameters() { 37 | return parameters; 38 | } 39 | 40 | /** 41 | * Set the command parameters. 42 | * @param parameters Command parameters. 43 | */ 44 | public void setParameters(List parameters) { 45 | this.parameters = parameters; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/scripting/ExecutionResult.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.scripting; 2 | 3 | import java.util.Map; 4 | 5 | public class ExecutionResult { 6 | 7 | private final State state; 8 | private final Map resultState; 9 | private final Map resultParameters; 10 | private final Object result; 11 | 12 | public ExecutionResult(State state, Map resultState, Map resultParameters, Object result) { 13 | this.state = state; 14 | this.resultState = resultState; 15 | this.resultParameters = resultParameters; 16 | this.result = result; 17 | } 18 | 19 | public final State getState() { 20 | return state; 21 | } 22 | 23 | public final Map getResultState() { 24 | return resultState; 25 | } 26 | 27 | public final Boolean isExecutionFailed() { 28 | return state.equals(State.FAIL); 29 | } 30 | 31 | public O getResult() { 32 | return (O) result; 33 | } 34 | 35 | public Map getResultParameters() { 36 | return resultParameters; 37 | } 38 | 39 | public enum State { 40 | FAIL,SUCCESS 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/messages/ResponseMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.messages; 2 | 3 | /** 4 | * This kind of messges are to send a response for a particular message. 5 | * @author javaito 6 | */ 7 | public class ResponseMessage extends Message { 8 | 9 | private Object value; 10 | private Throwable throwable; 11 | 12 | public ResponseMessage() { 13 | } 14 | 15 | public ResponseMessage(Message message) { 16 | super(message.getId()); 17 | } 18 | 19 | /** 20 | * Returns the response value. 21 | * @return Response value. 22 | */ 23 | public Object getValue() { 24 | return value; 25 | } 26 | 27 | /** 28 | * Set the response value. 29 | * @param value Response value. 30 | */ 31 | public void setValue(Object value) { 32 | this.value = value; 33 | } 34 | 35 | /** 36 | * Returns the throwable value. 37 | * @return Throwable value. 38 | */ 39 | public Throwable getThrowable() { 40 | return throwable; 41 | } 42 | 43 | /** 44 | * Set the throwable value. 45 | * @param throwable Throwable value. 46 | */ 47 | public void setThrowable(Throwable throwable) { 48 | this.throwable = throwable; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/Distinct.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | import org.hcjf.layers.query.Queryable; 4 | 5 | /** 6 | * Compare two object and return true if the objects are distinct and false in other ways. 7 | * @author javaito 8 | * 9 | */ 10 | public class Distinct extends Equals { 11 | 12 | public Distinct(Object leftValue, Object rightValue) { 13 | super(leftValue, rightValue); 14 | } 15 | 16 | /** 17 | * Evaluate if the evaluator's value and the object's value in the specified field of 18 | * the parameter instance are distinct. 19 | * This method support any kind of object like field value and parameter value too. 20 | * @param object Instance to obtain the field value. 21 | * @param dataSource Data source 22 | * @param consumer Data source consumer 23 | * @return True if the two values are distinct and false in other ways 24 | * @throws IllegalArgumentException If is impossible to get value from instance 25 | * with introspection. 26 | */ 27 | @Override 28 | public boolean evaluate(Object object, Queryable.DataSource dataSource, Queryable.Consumer consumer) { 29 | return !super.evaluate(object, dataSource, consumer); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/command/CommandRequestModel.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud.command; 2 | 3 | import org.hcjf.utils.bson.BsonParcelable; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Represents a command request. Specifies the command name and its associated payload. 9 | */ 10 | public class CommandRequestModel implements BsonParcelable { 11 | 12 | private String command; 13 | private Object instanceId; 14 | private Map payload; 15 | 16 | /** 17 | * The command name 18 | * @return the command name 19 | */ 20 | public String getCommand() { 21 | return command; 22 | } 23 | 24 | public void setCommand(String command) { 25 | this.command = command; 26 | } 27 | 28 | public Object getInstanceId() { 29 | return instanceId; 30 | } 31 | 32 | public void setInstanceId(Object instanceId) { 33 | this.instanceId = instanceId; 34 | } 35 | 36 | /** 37 | * The command's associated payload 38 | * @return the command's associated payload 39 | */ 40 | public Map getPayload() { 41 | return payload; 42 | } 43 | 44 | public void setPayload(Map payload) { 45 | this.payload = payload; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/resources/Resource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.resources; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.utils.Version; 5 | 6 | /** 7 | * @author javaito 8 | */ 9 | public abstract class Resource { 10 | 11 | private final Class layerClass; 12 | private final String resourceName; 13 | private final Version version; 14 | 15 | public Resource(Class layerClass, String resourceName, Version version) { 16 | this.layerClass = layerClass; 17 | this.resourceName = resourceName; 18 | this.version = version; 19 | } 20 | 21 | /** 22 | * Returns the layer class that implements the resource. 23 | * @return Layer class. 24 | */ 25 | public Class getLayerClass() { 26 | return layerClass; 27 | } 28 | 29 | /** 30 | * Returns the name of the resource. 31 | * @return Name of the resource. 32 | */ 33 | public String getResourceName() { 34 | return resourceName; 35 | } 36 | 37 | /** 38 | * Returns the version of the resource. 39 | * @return Version of the resource. 40 | */ 41 | public Version getVersion() { 42 | return version; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryJsonResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.JoinableMap; 4 | import org.hcjf.utils.JsonUtils; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.Map; 9 | 10 | public class QueryJsonResource extends QueryResource { 11 | 12 | private static final String TO_STRING_PATTERN = "'%s' as %s"; 13 | 14 | private final Collection resourceValues; 15 | 16 | public QueryJsonResource(String resourceName, Collection> resourceValues) { 17 | super(resourceName); 18 | this.resourceValues = new ArrayList<>(); 19 | for(Map value : resourceValues) { 20 | JoinableMap joinableMap = new JoinableMap(resourceName); 21 | joinableMap.setResource(resourceName); 22 | joinableMap.putAll(value); 23 | this.resourceValues.add(joinableMap); 24 | } 25 | } 26 | 27 | public Collection getResourceValues() { 28 | return resourceValues; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return String.format(TO_STRING_PATTERN, JsonUtils.toJsonTree(resourceValues).toString(), super.toString()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/Not.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | import org.hcjf.errors.HCJFRuntimeException; 4 | import org.hcjf.layers.query.Queryable; 5 | 6 | public class Not extends FieldEvaluator { 7 | 8 | public Not(Object leftValue) { 9 | super(leftValue, null); 10 | } 11 | 12 | /** 13 | * This method must be implemented for each particular implementation 14 | * to evaluate some details about instances of the data collection. 15 | * 16 | * @param object Object of the data collection. 17 | * @param dataSource Data source. 18 | * @param consumer Consumer. 19 | * @return Return true if the object must be part of the result add or false in the 20 | * other ways. 21 | */ 22 | @Override 23 | public boolean evaluate(Object object, Queryable.DataSource dataSource, Queryable.Consumer consumer) { 24 | boolean result; 25 | Object leftValue = getProcessedLeftValue(object, dataSource, consumer); 26 | 27 | if(leftValue instanceof Boolean) { 28 | result = !(Boolean) leftValue; 29 | } else { 30 | throw new HCJFRuntimeException("Not evaluator expecting a boolean expression"); 31 | } 32 | 33 | return result; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/io/net/http/ContextTest.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.net.MalformedURLException; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | public class ContextTest { 11 | 12 | static Map accessControlMap; 13 | 14 | 15 | @Test 16 | public void testOnOptions() throws MalformedURLException { 17 | accessControlMap = new HashMap<>(); 18 | String keyHeader = "http://localhost:5000"; 19 | String key = "localhost"; 20 | HttpServer.AccessControl accessControl = new HttpServer.AccessControl(key); 21 | accessControlMap.put(key, accessControl); 22 | HttpHeader httpHeader = new HttpHeader("ORIGIN", keyHeader); 23 | Context context = new Context("") { 24 | @Override 25 | public HttpResponse onContext(HttpRequest request) { 26 | return null; 27 | } 28 | }; 29 | 30 | HttpResponse response = context.onOptions(httpHeader, accessControlMap); 31 | Assert.assertNotNull(response); 32 | Assert.assertEquals(HttpResponseCode.OK, response.getResponseCode()); 33 | Assert.assertEquals(1, response.getHeaders().size()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/utils/io/net/http/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.utils.io.net.http; 2 | 3 | import org.hcjf.io.net.http.HttpServer; 4 | import org.hcjf.properties.SystemProperties; 5 | 6 | import java.util.Map; 7 | import java.util.regex.Pattern; 8 | 9 | public class HttpUtils { 10 | 11 | /** 12 | * This method is called for getting accessControl from a map. 13 | * @param host host information. 14 | * @param accessControlMap All the accessControlMap information. 15 | * @return Return an instance from the map of accessControlMap or null. 16 | */ 17 | public static HttpServer.AccessControl getAccessControl(String host, Map accessControlMap) { 18 | String startChar = SystemProperties.get(SystemProperties.Net.Http.HOST_ACCESS_CONTROL_REGEX_START_CHAR); 19 | for(String accessHost : accessControlMap.keySet()) { 20 | if(accessHost.startsWith(startChar)) { 21 | if(Pattern.matches(accessHost.substring(startChar.length()),host)) { 22 | return accessControlMap.get(accessHost); 23 | } 24 | } else if (accessHost.equals(host)) { 25 | return accessControlMap.get(accessHost); 26 | } 27 | } 28 | return null; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/ServiceDefinitionResponseMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.MessageCollection; 4 | 5 | import java.util.UUID; 6 | 7 | public class ServiceDefinitionResponseMessage extends MessageCollection { 8 | 9 | private UUID serviceId; 10 | private String serviceName; 11 | private Boolean broadcasting; 12 | private Boolean eventListener; 13 | 14 | public ServiceDefinitionResponseMessage() { 15 | } 16 | 17 | public UUID getServiceId() { 18 | return serviceId; 19 | } 20 | 21 | public void setServiceId(UUID serviceId) { 22 | this.serviceId = serviceId; 23 | } 24 | 25 | public String getServiceName() { 26 | return serviceName; 27 | } 28 | 29 | public void setServiceName(String serviceName) { 30 | this.serviceName = serviceName; 31 | } 32 | 33 | public Boolean getBroadcasting() { 34 | return broadcasting; 35 | } 36 | 37 | public void setBroadcasting(Boolean broadcasting) { 38 | this.broadcasting = broadcasting; 39 | } 40 | 41 | public Boolean getEventListener() { 42 | return eventListener; 43 | } 44 | 45 | public void setEventListener(Boolean eventListener) { 46 | this.eventListener = eventListener; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/network/NetworkComponent.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.network; 2 | 3 | import com.google.gson.Gson; 4 | import org.hcjf.service.ServiceConsumer; 5 | import org.hcjf.utils.bson.BsonParcelable; 6 | 7 | import java.util.Map; 8 | import java.util.UUID; 9 | 10 | /** 11 | * 12 | * @author javaito 13 | */ 14 | public class NetworkComponent implements ServiceConsumer, BsonParcelable { 15 | 16 | private UUID id; 17 | private String name; 18 | private Map kubernetesMetadata; 19 | 20 | private static final Gson gson; 21 | 22 | static { 23 | gson = new Gson(); 24 | } 25 | 26 | public UUID getId() { 27 | return id; 28 | } 29 | 30 | public void setId(UUID id) { 31 | this.id = id; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public Map getKubernetesMetadata() { 43 | return kubernetesMetadata; 44 | } 45 | 46 | public void setKubernetesMetadata(Map kubernetesMetadata) { 47 | this.kubernetesMetadata = kubernetesMetadata; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return gson.toJson(this); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/distributed/DistributedLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.distributed; 2 | 3 | import org.hcjf.cloud.Cloud; 4 | import org.hcjf.errors.HCJFRuntimeException; 5 | import org.hcjf.layers.Layer; 6 | import org.hcjf.layers.LayerInterface; 7 | 8 | import java.lang.reflect.Method; 9 | 10 | /** 11 | * This class is an interceptor component to make the distributed call. 12 | * @author javaito 13 | */ 14 | public final class DistributedLayer extends Layer { 15 | 16 | private final Class layerClass; 17 | 18 | public DistributedLayer(String implName, Class layerClass) { 19 | super(implName); 20 | this.layerClass = layerClass; 21 | } 22 | 23 | public Object invoke(Object proxy, Method method, Object[] args) { 24 | Object result; 25 | if(method.getDeclaringClass().equals(Object.class) || method.getDeclaringClass().equals(LayerInterface.class)) { 26 | try { 27 | result = method.invoke(this, args); 28 | } catch (Exception ex) { 29 | throw new HCJFRuntimeException("Distributed layer invoke fail", ex); 30 | } 31 | } else { 32 | result = Cloud.layerInvoke(layerClass, getImplName(), method, args); 33 | } 34 | return result; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryReturnLiteral.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | 5 | public class QueryReturnLiteral extends QueryParameter implements QueryReturnParameter { 6 | 7 | private final String alias; 8 | private final Object value; 9 | 10 | public QueryReturnLiteral(Query query, String originalValue, String valueToString, Object value, String alias) { 11 | super(query, originalValue, valueToString); 12 | this.alias = alias; 13 | this.value = value; 14 | } 15 | 16 | /** 17 | * Returns the literal value. 18 | * @return Literal value. 19 | */ 20 | public Object getValue() { 21 | return value; 22 | } 23 | 24 | /** 25 | * Return the field alias, can be null. 26 | * @return Field alias. 27 | */ 28 | @Override 29 | public String getAlias() { 30 | return alias; 31 | } 32 | 33 | /** 34 | * Verify if the query parameter make reference to the specified resource. 35 | * @param resource Resource instance to test. 36 | * @return Returns true if the parameter make reference to the specified resource and false in the otherwise. 37 | */ 38 | @Override 39 | public boolean verifyResource(QueryResource resource) { 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/Enlarged.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * This interface provides the functionality to extends the instance domain. 7 | * @author javaito. 8 | * 9 | */ 10 | public interface Enlarged { 11 | 12 | /** 13 | * Return the value that corresponds to the specific field name. 14 | * @param fieldName Field name. 15 | * @return Field value. 16 | */ 17 | Object get(String fieldName); 18 | 19 | /** 20 | * Add a new value to the instance. 21 | * @param key Name of the value. 22 | * @param value Value instance. 23 | * @return Return the value added. 24 | */ 25 | Object put(String key, Object value); 26 | 27 | /** 28 | * Returns the key set of the object. 29 | * @return Key set of the object 30 | */ 31 | Set keySet(); 32 | 33 | /** 34 | * Clone th enlarged object. 35 | * @param fields Array of static fields 36 | * @return Enlarged clone. 37 | */ 38 | Enlarged clone(String... fields); 39 | 40 | /** 41 | * Clone the enlarged object without domain information. 42 | * @return Enlarged clone. 43 | */ 44 | Enlarged cloneEmpty(); 45 | 46 | /** 47 | * This method remove all the fields that it's not static 48 | */ 49 | void purge(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/BaseQueryAggregateFunctionLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.layers.query.Queryable; 4 | import org.hcjf.layers.query.model.QueryReturnConditional; 5 | import org.hcjf.layers.query.model.QueryReturnField; 6 | import org.hcjf.layers.query.model.QueryReturnFunction; 7 | import org.hcjf.properties.SystemProperties; 8 | 9 | /** 10 | * @author javaito 11 | */ 12 | public abstract class BaseQueryAggregateFunctionLayer extends BaseFunctionLayer implements QueryAggregateFunctionLayerInterface { 13 | 14 | public BaseQueryAggregateFunctionLayer(String implName) { 15 | super(SystemProperties.get(SystemProperties.Query.Function.NAME_PREFIX) + implName); 16 | } 17 | 18 | protected O resolveValue(Object row, Object value) { 19 | Object result = value; 20 | if(result instanceof QueryReturnField) { 21 | result = ((QueryReturnField)result).resolve(row); 22 | } else if(result instanceof QueryReturnFunction) { 23 | result = new Queryable.IntrospectionConsumer<>().get(row, ((QueryReturnFunction)result), null); 24 | } else if(result instanceof QueryReturnConditional) { 25 | result = ((QueryReturnConditional)result).getEvaluationQuery().verifyCondition(row); 26 | } 27 | return (O) result; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/locale/PropertiesFileLocaleLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.locale; 2 | 3 | import org.hcjf.layers.Layer; 4 | import org.hcjf.log.Log; 5 | import org.hcjf.properties.SystemProperties; 6 | import org.hcjf.service.ServiceSession; 7 | 8 | import java.util.ResourceBundle; 9 | 10 | /** 11 | * This class use the java resource bundle api to translate the text 12 | * for the specific locale. 13 | * @author javaito 14 | */ 15 | public abstract class PropertiesFileLocaleLayer extends Layer implements LocaleLayerInterface { 16 | 17 | public PropertiesFileLocaleLayer(String implName) { 18 | super(implName); 19 | } 20 | 21 | /** 22 | * Changes the parameter string with the value into the bundle file indexed 23 | * by the parameter text. 24 | * @param text Text to translate. 25 | * @return Translated text or the same text if the are any error. 26 | */ 27 | @Override 28 | public String translate(String text) { 29 | String result = text; 30 | try { 31 | result = ResourceBundle.getBundle(getImplName(), ServiceSession.getCurrentIdentity().getLocale()).getString(text); 32 | } catch (Exception ex) { 33 | Log.w(SystemProperties.get(SystemProperties.Locale.LOG_TAG), 34 | "Unable to translate text (%s)", ex, text); 35 | } 36 | return result; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /getting-started.md: -------------------------------------------------------------------------------- 1 | # Getting started 2 | 3 | ## Java 4 | 5 | To use the latest version of HCJF you need to have java version 9 or higher installed in our operating system 6 | 7 | - [Ubuntu](http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html) 8 | - [Linux](https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-linux-platforms.htm#JSJIG-GUID-737A84E4-2EFF-4D38-8E60-3E29D1B884B8) 9 | - [Windows](https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-microsoft-windows-platforms.htm#JSJIG-GUID-A7E27B90-A28D-4237-9383-A58B416071CA) 10 | - [Mac OS](https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-macos.htm#JSJIG-GUID-F9183C70-2E96-40F4-9104-F3814A5A331F) 11 | 12 | ## Dependencies 13 | 14 | After java is already configured in your operating system you have to add the dependencies jar in your class path so that the virtual machine finds the dependencies. Doing this work without using any tool for the administration of dependencies can be complicated since each dependency can contain sub-dependencies and it would be difficult to find each of them. I recommend using [maven](https://maven.apache.org/guides/getting-started/index.html) for this task, just add the following code in your pom.xml file 15 | ```xml 16 | 17 | com.github.javaito 18 | hcjf 19 | 1.3.43 20 | 21 | ``` -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/ReadLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.layers.query.Queryable; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public interface ReadLayerInterface extends LayerInterface { 12 | 13 | /** 14 | * This method implements the read operation to find an instance of 15 | * the resource using only it's id. 16 | * @param id Id to found the instance. 17 | * @return Return the instance founded or null if the instance is not found. 18 | */ 19 | default O read(Object id) { 20 | throw new UnsupportedOperationException(); 21 | } 22 | 23 | /** 24 | * This method implements the read operation without filters. 25 | * @return List with all the instances of the resource. 26 | */ 27 | default Collection read() { 28 | throw new UnsupportedOperationException(); 29 | } 30 | 31 | /** 32 | * This method implements the read operation using the filters 33 | * specified in the query. 34 | * @param queryable Instance that contains all the information to evaluate a query. 35 | * @return Return the list with the instances founded. 36 | */ 37 | default Collection read(Queryable queryable) { 38 | throw new UnsupportedOperationException(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/io/net/http/HttpSimpleServer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http; 2 | 3 | import org.hcjf.properties.SystemProperties; 4 | 5 | public class HttpSimpleServer { 6 | 7 | public static void main(String[] args) { 8 | 9 | System.setProperty(SystemProperties.Log.SYSTEM_OUT_ENABLED, "false"); 10 | System.setProperty(SystemProperties.Log.LEVEL, "1"); 11 | System.setProperty(SystemProperties.Net.Ssl.DEFAULT_KEYSTORE_FILE_PATH, 12 | "/home/javaito/Git/HolandaCatalinaFw/src/main/resources/org/hcjf/io/net/https/keystore.jks"); 13 | System.setProperty(SystemProperties.Net.Ssl.DEFAULT_TRUSTED_CERTS_FILE_PATH, 14 | "/home/javaito/Git/HolandaCatalinaFw/src/main/resources/org/hcjf/io/net/https/cacerts.jks"); 15 | 16 | HttpResponse response = new HttpResponse(); 17 | response.setResponseCode(200); 18 | response.setBody("Hello world".getBytes()); 19 | HttpServer.create(9090, new Context(".*") { 20 | @Override 21 | public HttpResponse onContext(HttpRequest httpRequest) { 22 | return response; 23 | } 24 | }); 25 | 26 | // HttpServer.create(8080, new Context(".*") { 27 | // @Override 28 | // public HttpResponse onContext(HttpRequest httpRequest) { 29 | // return response; 30 | // } 31 | // }); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/LayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers; 2 | 3 | import org.hcjf.layers.distributed.DistributedLayer; 4 | 5 | import java.lang.reflect.InvocationHandler; 6 | 7 | /** 8 | * @author javaito 9 | * 10 | */ 11 | public interface LayerInterface extends InvocationHandler { 12 | 13 | /** 14 | * Return the layer implementation name. 15 | * @return Layer implementation name. 16 | */ 17 | String getImplName(); 18 | 19 | /** 20 | * Returns a regex to math, this regex only gonna by used if the get layer method not found any layer with the 21 | * specific name. 22 | * @return Regex value. Null by default. 23 | */ 24 | default String getRegex() { 25 | return null; 26 | } 27 | 28 | /** 29 | * Returns true if the layer is stateful or false in the otherwise. 30 | * @return Stateful 31 | */ 32 | boolean isStateful(); 33 | 34 | /** 35 | * Returns true if the layer is a plugin or false in the otherwise. 36 | * @return Plugin status. 37 | */ 38 | boolean isPlugin(); 39 | 40 | /** 41 | * Returns true if the layer implementation is instance of {@link DistributedLayer}. 42 | * @return True if the layer implementation is instance of {@link DistributedLayer} and false in the otherwise. 43 | */ 44 | default boolean isDistributed() { 45 | return this instanceof DistributedLayer; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/And.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | import org.hcjf.layers.query.Queryable; 4 | import org.hcjf.layers.query.model.QueryParameter; 5 | 6 | /** 7 | * 8 | * @author javaito 9 | */ 10 | public class And extends EvaluatorCollection implements Evaluator { 11 | 12 | public And(EvaluatorCollection parent) { 13 | super(parent); 14 | } 15 | 16 | /** 17 | * Makes a and concatenation with all the inner evaluators 18 | * @param object Object of the data collection. 19 | * @param dataSource Data source. 20 | * @param consumer Consumer. 21 | * @return Returns the result of the concatenation. 22 | */ 23 | @Override 24 | public boolean evaluate(Object object, Queryable.DataSource dataSource, Queryable.Consumer consumer) { 25 | boolean result = true; 26 | 27 | for(Evaluator evaluator : getEvaluators()) { 28 | if (evaluator instanceof BooleanEvaluator && 29 | ((BooleanEvaluator) evaluator).getValue() instanceof QueryParameter && 30 | ((QueryParameter)((BooleanEvaluator) evaluator).getValue()).isUnderlying()) { 31 | continue; 32 | } 33 | result &= evaluator.evaluate(object, dataSource, consumer); 34 | if(!result) { 35 | break; 36 | } 37 | } 38 | 39 | return result; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/MinAggregateFunctionLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.errors.HCJFRuntimeException; 4 | 5 | import java.util.Collection; 6 | import java.util.Map; 7 | 8 | public class MinAggregateFunctionLayer extends BaseQueryAggregateFunctionLayer implements NumberSetFunction { 9 | 10 | public static final String NAME = "aggregateMin"; 11 | 12 | public MinAggregateFunctionLayer() { 13 | super(NAME); 14 | } 15 | 16 | @Override 17 | public Collection evaluate(String alias, Collection resultSet, Object... parameters) { 18 | Collection result = resultSet; 19 | if(parameters.length >= 1) { 20 | try { 21 | Number accumulatedValue; 22 | for(Object row : resultSet) { 23 | accumulatedValue = Double.MAX_VALUE; 24 | accumulatedValue = accumulateFunction(accumulatedValue, new Object[]{resolveValue(row, parameters[0])}, (A,V)-> A.compareTo(V) <= 0 ? A : V)[1]; 25 | ((Map)row).put(alias, accumulatedValue); 26 | } 27 | } catch (Exception ex){ 28 | throw new HCJFRuntimeException("Min aggregate function fail", ex); 29 | } 30 | } else { 31 | throw new HCJFRuntimeException("Min aggregate function need at leas one parameter"); 32 | } 33 | return result; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/layers/cache/SubLayerCache.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.cache; 2 | 3 | import org.hcjf.layers.Layer; 4 | 5 | import java.util.Map; 6 | 7 | public class SubLayerCache extends Layer implements CacheLayerInterface> { 8 | 9 | private Map value; 10 | private CacheServiceConsumer cacheServiceConsumer; 11 | 12 | 13 | @Override 14 | public String getImplName() { 15 | return "subLayer"; 16 | } 17 | 18 | /** 19 | * This method invalidate the values into cache and restore its using the datasource associated to the cache. 20 | */ 21 | @Override 22 | public void invalidate() { 23 | if(cacheServiceConsumer == null) { 24 | cacheServiceConsumer = new CacheServiceConsumer("map"); 25 | CacheService.getInstance().registerConsumer(cacheServiceConsumer); 26 | } 27 | value = cacheServiceConsumer.get(); 28 | } 29 | 30 | /** 31 | * Returns the timeout value, this value indicates the time that the cache is valid. 32 | * 33 | * @return Timeout value. 34 | */ 35 | @Override 36 | public Long timout() { 37 | return 5000L; 38 | } 39 | 40 | /** 41 | * This method returns a current values of the cache. 42 | * 43 | * @return Current value of the cache. 44 | */ 45 | @Override 46 | public Map get() { 47 | return value; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/layers/cache/SubLayerCache2.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.cache; 2 | 3 | import org.hcjf.layers.Layer; 4 | 5 | import java.util.Map; 6 | 7 | public class SubLayerCache2 extends Layer implements CacheLayerInterface> { 8 | 9 | private Map value; 10 | private CacheServiceConsumer cacheServiceConsumer; 11 | 12 | 13 | @Override 14 | public String getImplName() { 15 | return "subLayer2"; 16 | } 17 | 18 | /** 19 | * This method invalidate the values into cache and restore its using the datasource associated to the cache. 20 | */ 21 | @Override 22 | public void invalidate() { 23 | if(cacheServiceConsumer == null) { 24 | cacheServiceConsumer = new CacheServiceConsumer("map"); 25 | CacheService.getInstance().registerConsumer(cacheServiceConsumer); 26 | } 27 | value = cacheServiceConsumer.get(); 28 | } 29 | 30 | /** 31 | * Returns the timeout value, this value indicates the time that the cache is valid. 32 | * 33 | * @return Timeout value. 34 | */ 35 | @Override 36 | public Long timout() { 37 | return 15000L; 38 | } 39 | 40 | /** 41 | * This method returns a current values of the cache. 42 | * 43 | * @return Current value of the cache. 44 | */ 45 | @Override 46 | public Map get() { 47 | return value; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/utils/CryptographyTestSuite.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.utils; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.UUID; 7 | 8 | 9 | /** 10 | * @author Andres Medina 11 | */ 12 | public class CryptographyTestSuite { 13 | 14 | private static final String message = "Las máquinas me sorprenden con mucha frecuencia"; 15 | private static final String encryptedMessage = "b72159963a9a6a877f276a6fd08dfd920e1a532d3570b853a6103d0db8f28c100001fd776a28e9419eab7050c9cc2a56a9134f48fff2969643627cdc0a6f36c49826f27fb9834ddff8445346ca6b57c601edf583db62a1369864dfd539f81b0f46f672282ac36df0efde06845b6adef64393fb517009784fa2ca493e88b16feb713e9d24bca4ef163c64f3b82cc4f48e9a95b3c4f8d030a0448fa7ac8f8c99d3"; 16 | byte[] test; 17 | 18 | @Test(timeout = 20000) 19 | public void encrypt() { 20 | Cryptography crypt = new Cryptography();//(key,"RandomIVTestService","HolandaCatalinaCrypt","AES","GCM","PKCS5Padding",128); 21 | for (int i = 0; i < 1000000; i++) { 22 | crypt.encrypt((message + i).getBytes()); 23 | } 24 | } 25 | 26 | @Test 27 | public void decrypt() { 28 | Cryptography crypt = new Cryptography();//(key,"RandomIVTestService","HolandaCatalinaCrypt","AES","GCM","PKCS5Padding",128); 29 | String messageResult = new String(crypt.decrypt(Strings.hexToBytes(encryptedMessage))); 30 | Assert.assertEquals(message,messageResult); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/DistinctQueryAggregateFunction.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.layers.query.model.QueryReturnField; 4 | import org.hcjf.utils.Strings; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.HashSet; 9 | import java.util.Set; 10 | 11 | public class DistinctQueryAggregateFunction extends BaseQueryAggregateFunctionLayer { 12 | 13 | private static final String NAME = "distinct"; 14 | 15 | public DistinctQueryAggregateFunction() { 16 | super(NAME); 17 | } 18 | 19 | @Override 20 | public Collection evaluate(String alias, Collection resultSet, Object... parameters) { 21 | Collection result = new ArrayList(); 22 | Collection fields = new ArrayList<>(); 23 | for(Object param : parameters) { 24 | fields.add((QueryReturnField) param); 25 | } 26 | 27 | Set hashSet = new HashSet<>(); 28 | String hash; 29 | for(Object row : resultSet) { 30 | hash = Strings.EMPTY_STRING; 31 | for(QueryReturnField field : fields) { 32 | hash += Integer.toString(field.resolve(row).hashCode()); 33 | } 34 | if(!hashSet.contains(hash)) { 35 | hashSet.add(hash); 36 | result.add(row); 37 | } 38 | } 39 | 40 | return result; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/log/LogMessages.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.log; 2 | 3 | import org.hcjf.properties.SystemProperties; 4 | import org.hcjf.utils.Messages; 5 | 6 | /** 7 | * @author javaito 8 | * 9 | */ 10 | public final class LogMessages extends Messages { 11 | 12 | private static final LogMessages instance; 13 | 14 | static { 15 | instance = new LogMessages(); 16 | } 17 | 18 | private LogMessages() { 19 | } 20 | 21 | @Override 22 | protected Class getLocaleLayerImplementation(){ 23 | return SystemProperties.getClass(SystemProperties.Locale.DEFAULT_LOCALE_LAYER_IMPLEMENTATION_CLASS_NAME); 24 | } 25 | 26 | /** 27 | * Return the message associated to the log code. 28 | * @param logCode Log code. 29 | * @param params Parameters to complete the message. 30 | * @return Message complete and translated. 31 | */ 32 | public static String getMessage(String logCode, Object... params) { 33 | return instance.getInternalMessage( 34 | logCode, 35 | SystemProperties.get(SystemProperties.Locale.DEFAULT_LOCALE_LAYER_IMPLEMENTATION_NAME), 36 | params); 37 | } 38 | 39 | /** 40 | * Add the default value associated to log code. 41 | * @param logCode Log code. 42 | * @param defaultMessage Default message. 43 | */ 44 | public static void addDefault(String logCode, String defaultMessage) { 45 | instance.addInternalDefault(logCode, defaultMessage); 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/BaseFunctionLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.errors.HCJFRuntimeException; 4 | import org.hcjf.layers.Layer; 5 | 6 | /** 7 | * @author javaito 8 | */ 9 | public abstract class BaseFunctionLayer extends Layer { 10 | 11 | public BaseFunctionLayer(String implName) { 12 | super(implName); 13 | } 14 | 15 | /** 16 | * This utils method returns a specific parameter and cast it with the expected type in the invoker. 17 | * @param index Argument index. 18 | * @param parameters Arguments array. 19 | * @param Expected data type for the invoker. 20 | * @return Parameter value. 21 | */ 22 | protected O getParameter(int index, Object... parameters) { 23 | try { 24 | Object result = parameters[index]; 25 | if(result instanceof Throwable) { 26 | throw new HCJFRuntimeException("Inner function fail parameter index: %d", (Throwable)result, index); 27 | } 28 | return (O) result; 29 | } catch (ClassCastException ex) { 30 | throw new HCJFRuntimeException("Illegal argument type, %d° argument", ex, index); 31 | } catch (IndexOutOfBoundsException ex) { 32 | throw new HCJFRuntimeException("Wrong number of arguments, getting %d° argument", ex, index); 33 | } catch (Exception ex) { 34 | throw new HCJFRuntimeException("Unexpected error getting %d° argument", ex, index); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/Or.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | import org.hcjf.layers.query.Queryable; 4 | import org.hcjf.layers.query.model.QueryParameter; 5 | 6 | /** 7 | * Evaluate all the evaluators into the collection and concat all the result with or operation. 8 | * @author javaito 9 | */ 10 | public class Or extends EvaluatorCollection implements Evaluator { 11 | 12 | public Or(EvaluatorCollection parent) { 13 | super(parent); 14 | } 15 | 16 | /** 17 | * Evaluate all the inner evaluators. 18 | * @param object Object of the data collection. 19 | * @param dataSource Data source. 20 | * @param consumer Consumer. 21 | * @return Returns the value of the concat all the values. 22 | */ 23 | @Override 24 | public boolean evaluate(Object object, Queryable.DataSource dataSource, Queryable.Consumer consumer) { 25 | boolean result = false; 26 | 27 | for(Evaluator evaluator : getEvaluators()) { 28 | if (evaluator instanceof BooleanEvaluator && 29 | ((BooleanEvaluator) evaluator).getValue() instanceof QueryParameter && 30 | ((QueryParameter)((BooleanEvaluator) evaluator).getValue()).isUnderlying()) { 31 | result = true; 32 | } else { 33 | result |= evaluator.evaluate(object, dataSource, consumer); 34 | } 35 | if(result) { 36 | break; 37 | } 38 | } 39 | 40 | return result; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryFunction.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | 5 | import java.util.List; 6 | import java.util.Set; 7 | import java.util.TreeSet; 8 | 9 | /** 10 | * 11 | */ 12 | public class QueryFunction extends QueryParameter { 13 | 14 | private final String functionName; 15 | private final List parameters; 16 | 17 | public QueryFunction(Query query, String originalFunction, String functionName, List parameters) { 18 | super(query, originalFunction, functionName); 19 | this.functionName = functionName; 20 | this.parameters = parameters; 21 | } 22 | 23 | public String getFunctionName() { 24 | return functionName; 25 | } 26 | 27 | public List getParameters() { 28 | return parameters; 29 | } 30 | 31 | public Set getResources() { 32 | Set queryResources = new TreeSet<>(); 33 | 34 | for(Object parameter : parameters) { 35 | if(parameter instanceof QueryField) { 36 | queryResources.add(((QueryField)parameter).getResource()); 37 | } else if(parameter instanceof QueryFunction) { 38 | queryResources.addAll(((QueryFunction)parameter).getResources()); 39 | } 40 | } 41 | 42 | return queryResources; 43 | } 44 | 45 | @Override 46 | public boolean verifyResource(QueryResource resource) { 47 | return getResources().contains(resource); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/DataFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class DataFrame extends Http2Frame { 6 | 7 | private Byte pathLength; 8 | private ByteBuffer padding; 9 | private ByteBuffer data; 10 | 11 | public DataFrame(Integer id, Byte flags, Integer length) { 12 | super(id, flags, length, Type.DATA); 13 | } 14 | 15 | public Byte getPathLength() { 16 | return pathLength; 17 | } 18 | 19 | public void setPathLength(Byte pathLength) { 20 | this.pathLength = pathLength; 21 | } 22 | 23 | public ByteBuffer getPadding() { 24 | return padding; 25 | } 26 | 27 | public void setPadding(ByteBuffer padding) { 28 | this.padding = padding; 29 | } 30 | 31 | public ByteBuffer getData() { 32 | return data; 33 | } 34 | 35 | public void setData(ByteBuffer data) { 36 | this.data = data; 37 | } 38 | 39 | @Override 40 | protected Integer recalculateLength() { 41 | return getData().limit() + (getPadding() != null ? getPadding().limit() : 0) + 1; 42 | } 43 | 44 | @Override 45 | protected void processPayload() { 46 | } 47 | 48 | @Override 49 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 50 | fixedBuffer.put(getPathLength()); 51 | fixedBuffer.put(getData()); 52 | if(getPathLength() > 0) { 53 | fixedBuffer.put(getPadding()); 54 | } 55 | return fixedBuffer; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/evaluators/BooleanEvaluator.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.evaluators; 2 | 3 | import org.hcjf.layers.query.Queryable; 4 | 5 | /** 6 | * @author javaito 7 | */ 8 | public class BooleanEvaluator extends BaseEvaluator { 9 | 10 | private final Object value; 11 | 12 | public BooleanEvaluator(Object value) { 13 | this.value = value; 14 | } 15 | 16 | public final Object getValue() { 17 | return value; 18 | } 19 | 20 | @Override 21 | public boolean evaluate(Object object, Queryable.DataSource dataSource, Queryable.Consumer consumer) { 22 | Object processedValue = getProcessedValue(object, getValue(), dataSource, consumer); 23 | Boolean result = false; 24 | if (processedValue != null) { 25 | if (processedValue instanceof Boolean) { 26 | result = (Boolean) processedValue; 27 | } else if (boolean.class.equals(processedValue.getClass())) { 28 | result = (boolean) processedValue; 29 | } else if (Number.class.isAssignableFrom(processedValue.getClass())) { 30 | result = ((Number) processedValue).intValue() != 0; 31 | } else if (processedValue instanceof String) { 32 | result = Boolean.parseBoolean((String) processedValue); 33 | } else { 34 | throw new IllegalArgumentException("Value evaluator only supports boolean values or functions that response with boolean values."); 35 | } 36 | } 37 | return result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/proxy/RedirectionRule.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.proxy; 2 | 3 | import org.hcjf.io.net.http.HttpClient; 4 | import org.hcjf.io.net.http.HttpHeader; 5 | import org.hcjf.io.net.http.HttpRequest; 6 | import org.hcjf.io.net.http.HttpResponse; 7 | 8 | import java.net.URL; 9 | 10 | /** 11 | * Proxy task that implements a redirection rule. 12 | * @author javaito 13 | */ 14 | public class RedirectionRule extends HttpProxyRule { 15 | 16 | private final String contextRegex; 17 | private final URL url; 18 | 19 | public RedirectionRule(String contextRegex, URL url) { 20 | this.contextRegex = contextRegex; 21 | this.url = url; 22 | } 23 | 24 | @Override 25 | public boolean evaluate(HttpRequest request) { 26 | return request.getContext().matches(contextRegex); 27 | } 28 | 29 | @Override 30 | public ProxyTask getTask() { 31 | return new RedirectionTask(); 32 | } 33 | 34 | private class RedirectionTask extends ProxyTask { 35 | 36 | private HttpResponse response; 37 | 38 | @Override 39 | public HttpResponse execute(HttpRequest request) { 40 | HttpClient client = new HttpClient(url); 41 | client.setHttpMethod(request.getMethod()); 42 | //TODO: Set body 43 | request.getHeaders().stream().filter( 44 | header -> !header.getHeaderName().equals(HttpHeader.HOST)) 45 | .forEach(client::addHttpHeader); 46 | return client.request(); 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/utils/TTLMapTest.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.utils; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.util.HashMap; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public class TTLMapTest { 12 | 13 | @Test 14 | public void testTtlMap() { 15 | TtlMap ttlMap = new TtlMap<>(new HashMap<>(), 1000L); 16 | ttlMap.put("hello", "world"); 17 | 18 | Assert.assertNotNull(ttlMap.get("hello")); 19 | 20 | try { 21 | Thread.sleep(1001); 22 | } catch (InterruptedException e) { 23 | } 24 | 25 | Assert.assertNull(ttlMap.get("hello")); 26 | } 27 | 28 | @Test 29 | public void testTtlAndLru() throws InterruptedException { 30 | TtlMap superMap = new TtlMap<>(new LruMap<>(3), 5000L); 31 | 32 | superMap.put("1°","1°"); 33 | Thread.sleep(10); 34 | 35 | superMap.put("2°","2°"); 36 | Thread.sleep(10); 37 | 38 | superMap.put("3°","3°"); 39 | Thread.sleep(10); 40 | 41 | superMap.put("4°","4°"); 42 | 43 | Assert.assertTrue(!superMap.containsKey("1°")); 44 | Assert.assertTrue(superMap.containsKey("2°")); 45 | Assert.assertTrue(superMap.containsKey("3°")); 46 | Assert.assertTrue(superMap.containsKey("4°")); 47 | 48 | Thread.sleep(5500); 49 | 50 | Assert.assertTrue(superMap.isEmpty()); 51 | 52 | superMap.put("3°","3°"); 53 | Thread.sleep(10); 54 | 55 | Assert.assertTrue(superMap.containsKey("3°")); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /.github/workflows/jfrog.yaml: -------------------------------------------------------------------------------- 1 | name: Build and Upload to JFrog 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | tests: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout Repository 14 | uses: actions/checkout@v4 15 | 16 | - name: Set up JDK 12 17 | uses: actions/setup-java@v4 18 | with: 19 | distribution: 'adopt' 20 | java-version: '12' 21 | 22 | - name: Run Tests 23 | run: mvn test 24 | 25 | deploy: 26 | needs: tests 27 | runs-on: ubuntu-latest 28 | 29 | steps: 30 | - name: Checkout Repository 31 | uses: actions/checkout@v4 32 | 33 | - name: Set up JDK 12 34 | uses: actions/setup-java@v4 35 | with: 36 | distribution: 'adopt' 37 | java-version: '12' 38 | 39 | - name: Get Tag Name 40 | id: tag_name 41 | run: echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT 42 | 43 | - name: Deploy to Jfrog 44 | env: 45 | USER: ${{ secrets.CI_JFROG_USERNAME }} 46 | PASS: ${{ secrets.CI_JFROG_PASSWORD }} 47 | run: mvn deploy --settings settings.xml -Dversion=${{ steps.tag_name.outputs.TAG }} -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dgpg.skip -P jfrog -Denv.CI_JFROG_USERNAME=${USER} -Denv.CI_JFROG_PASSWORD=${PASS} 48 | 49 | - name: Deploy to Maven 50 | env: 51 | PHRASE: ${{ secrets.CI_MAVEN_GPG_PHRASE }} 52 | run: mvn deploy --settings settings.xml -Dversion=${{ steps.tag_name.outputs.TAG }} -Dgpg.passphrase=${PHRASE} -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/network/CloudServer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.network; 2 | 3 | import org.hcjf.cloud.impl.messages.ShutdownMessage; 4 | import org.hcjf.io.net.NetPackage; 5 | import org.hcjf.io.net.NetService; 6 | import org.hcjf.io.net.messages.Message; 7 | import org.hcjf.io.net.messages.MessageBuffer; 8 | import org.hcjf.io.net.messages.MessagesServer; 9 | import org.hcjf.properties.SystemProperties; 10 | 11 | /** 12 | * @author javaito 13 | */ 14 | public class CloudServer extends MessagesServer { 15 | 16 | public CloudServer() { 17 | super(SystemProperties.getInteger(SystemProperties.Cloud.Orchestrator.SERVER_LISTENER_PORT), 18 | NetService.TransportLayerProtocol.TCP, 19 | false, true); 20 | } 21 | 22 | @Override 23 | public CloudSession createSession(NetPackage netPackage) { 24 | CloudSession session = new CloudSession( this); 25 | return session; 26 | } 27 | 28 | @Override 29 | public CloudSession checkSession(CloudSession session, MessageBuffer payLoad, NetPackage netPackage) { 30 | return session; 31 | } 32 | 33 | @Override 34 | protected MessageBuffer getShutdownPackage(CloudSession session) { 35 | MessageBuffer messageBuffer = new MessageBuffer(); 36 | messageBuffer.append(new ShutdownMessage(session)); 37 | return messageBuffer; 38 | } 39 | 40 | @Override 41 | protected void onRead(CloudSession session, Message message) { 42 | CloudOrchestrator.getInstance().incomingMessage(session, message); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.utils.Strings; 4 | 5 | /** 6 | * Represents any kind of resource. 7 | */ 8 | public class QueryResource implements Comparable, QueryComponent { 9 | 10 | public static final QueryResource ANY = new QueryResource(Strings.ALL); 11 | 12 | private String resourceName; 13 | 14 | public QueryResource(String resourceName) { 15 | this.resourceName = resourceName; 16 | } 17 | 18 | /** 19 | * Set the name of the resource. 20 | * @param resourceName Name of the resource 21 | */ 22 | public void setResourceName(String resourceName) { 23 | this.resourceName = resourceName; 24 | } 25 | 26 | /** 27 | * Return the resource name. 28 | * @return Resource name. 29 | */ 30 | public String getResourceName() { 31 | return resourceName; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | boolean result = false; 37 | if(obj instanceof QueryResource) { 38 | result = resourceName.equals(((QueryResource)obj).getResourceName()); 39 | } 40 | return result; 41 | } 42 | 43 | @Override 44 | public boolean isUnderlying() { 45 | return false; 46 | } 47 | 48 | @Override 49 | public int compareTo(QueryResource o) { 50 | return resourceName.compareTo(o.getResourceName()); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return getResourceName(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /examples/org/hcjf/examples/salary/EmployeeResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.examples.salary; 2 | 3 | import org.hcjf.layers.Layer; 4 | import org.hcjf.layers.crud.CreateLayerInterface; 5 | import org.hcjf.layers.crud.ReadLayerInterface; 6 | import org.hcjf.layers.crud.ReadRowsLayerInterface; 7 | import org.hcjf.layers.distributed.DistributedLayerInterface; 8 | import org.hcjf.layers.query.JoinableMap; 9 | import org.hcjf.layers.query.Queryable; 10 | 11 | import java.util.*; 12 | 13 | public class EmployeeResource extends Layer implements CreateLayerInterface>, 14 | ReadLayerInterface>, 15 | ReadRowsLayerInterface, 16 | DistributedLayerInterface { 17 | 18 | private Map> db; 19 | 20 | public EmployeeResource() { 21 | db = new HashMap<>(); 22 | } 23 | 24 | @Override 25 | public String getImplName() { 26 | return "employee"; 27 | } 28 | 29 | @Override 30 | public Map create(Map employee) { 31 | UUID id = UUID.randomUUID(); 32 | employee.put("id", id); 33 | db.put(id, employee); 34 | return employee; 35 | } 36 | 37 | @Override 38 | public Map read(Object id) { 39 | return db.get(id); 40 | } 41 | 42 | @Override 43 | public Collection readRows(Queryable queryable) { 44 | Collection result = new ArrayList<>(); 45 | db.values().forEach(M -> result.add(new JoinableMap(M))); 46 | return queryable.evaluate(result); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/crud/UpdateLayerInterface.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.crud; 2 | 3 | import org.hcjf.layers.LayerInterface; 4 | import org.hcjf.layers.query.Queryable; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * @author javaito 10 | */ 11 | public interface UpdateLayerInterface extends LayerInterface { 12 | 13 | /** 14 | * This method implements the update of the resource. 15 | * @param object Instance of the resource that gonna be updated. 16 | * This instance must have an id to identify the updatable data. 17 | * @return The instance updated. 18 | */ 19 | default O update(O object) { 20 | throw new UnsupportedOperationException(); 21 | } 22 | 23 | /** 24 | * This method implements the update for many object in the same call. 25 | * @param objects Objects to update. 26 | * @return The instances updated. 27 | */ 28 | default Collection update(Collection objects) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | 32 | /** 33 | * This method implements the update operation over a add of the instances, 34 | * this instances are selected using the query like a match. 35 | * @param queryable Instance that contains all the information to evaluate a query. 36 | * @param object Contains the values for all the instances that found the query evaluation. 37 | * @return Return the instances updated. 38 | */ 39 | default Collection update(Queryable queryable, O object) { 40 | throw new UnsupportedOperationException(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryReturnFunction.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.Layers; 4 | import org.hcjf.layers.query.Query; 5 | import org.hcjf.layers.query.functions.QueryAggregateFunctionLayerInterface; 6 | import org.hcjf.properties.SystemProperties; 7 | 8 | import java.util.List; 9 | 10 | public class QueryReturnFunction extends QueryFunction implements QueryReturnParameter { 11 | 12 | private final String alias; 13 | private boolean aggregate; 14 | 15 | public QueryReturnFunction(Query query, String originalFunction, String functionName, List parameters, String alias) { 16 | super(query, originalFunction, functionName, parameters); 17 | 18 | aggregate = false; 19 | try { 20 | Layers.get(QueryAggregateFunctionLayerInterface.class, 21 | SystemProperties.get(SystemProperties.Query.Function.NAME_PREFIX) +functionName); 22 | aggregate = true; 23 | } catch (Exception ex){} 24 | 25 | if(alias != null) { 26 | this.alias = alias; 27 | } else { 28 | this.alias = originalFunction; 29 | } 30 | } 31 | 32 | /** 33 | * Return the field alias, can be null. 34 | * @return Field alias. 35 | */ 36 | public String getAlias() { 37 | return alias; 38 | } 39 | 40 | /** 41 | * Verify if the function is an aggregate function or not. 42 | * @return True if the function is an aggregate function and false in the otherwise. 43 | */ 44 | public boolean isAggregate() { 45 | return aggregate; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/layers/scripting/PythonCodeTest.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.scripting; 2 | 3 | //import org.python.util.PythonInterpreter; 4 | // 5 | //import javax.script.ScriptContext; 6 | //import javax.script.ScriptEngine; 7 | //import javax.script.ScriptEngineManager; 8 | //import java.io.StringWriter; 9 | //import java.util.Properties; 10 | 11 | public class PythonCodeTest { 12 | 13 | 14 | public static void main(String[] args) { 15 | // StringWriter writer = new StringWriter(); 16 | // ScriptContext context = new SimpleScriptContext(); 17 | // context.setWriter(writer); 18 | // 19 | // ScriptEngineManager manager = new ScriptEngineManager(); 20 | // ScriptEngine engine = manager.getEngineByName("python"); 21 | // engine.eval(new FileReader(resolvePythonScriptPath("hello.py")), context); 22 | // 23 | 24 | // try (PythonInterpreter pyInterp = new PythonInterpreter()) { 25 | // StringWriter output = new StringWriter(); 26 | // pyInterp.setOut(output); 27 | // 28 | // pyInterp.exec("properties = {\n" + 29 | // " \"Key1\": \"value1\",\n" + 30 | // " \"key2\": 3.5\n" + 31 | // "}\n" + 32 | // "\n" + 33 | // "if properties[\"Key1\"] == \"value1\":\n" + 34 | // " print(\"El valor era correcto\")\n" + 35 | // "print(properties[\"key2\"] + 5)"); 36 | //// System.out.println(pyInterp.get("result").toString()); 37 | // System.out.println(output.toString().trim()); 38 | // } 39 | } 40 | 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/ServiceDefinitionMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.MessageCollection; 4 | 5 | import java.util.List; 6 | import java.util.UUID; 7 | 8 | public class ServiceDefinitionMessage extends MessageCollection { 9 | 10 | private UUID serviceId; 11 | private String serviceName; 12 | private Boolean broadcasting; 13 | private Boolean eventListener; 14 | private List distributedEventListenerFilter; 15 | 16 | public UUID getServiceId() { 17 | return serviceId; 18 | } 19 | 20 | public void setServiceId(UUID serviceId) { 21 | this.serviceId = serviceId; 22 | } 23 | 24 | public String getServiceName() { 25 | return serviceName; 26 | } 27 | 28 | public void setServiceName(String serviceName) { 29 | this.serviceName = serviceName; 30 | } 31 | 32 | public Boolean getBroadcasting() { 33 | return broadcasting; 34 | } 35 | 36 | public void setBroadcasting(Boolean broadcasting) { 37 | this.broadcasting = broadcasting; 38 | } 39 | 40 | public Boolean getEventListener() { 41 | return eventListener; 42 | } 43 | 44 | public void setEventListener(Boolean eventListener) { 45 | this.eventListener = eventListener; 46 | } 47 | 48 | public List getDistributedEventListenerFilter() { 49 | return distributedEventListenerFilter; 50 | } 51 | 52 | public void setDistributedEventListenerFilter(List distributedEventListenerFilter) { 53 | this.distributedEventListenerFilter = distributedEventListenerFilter; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryReturnConditional.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | 5 | public class QueryReturnConditional extends QueryParameter implements QueryConditional, QueryReturnParameter { 6 | 7 | private static final String QUERY_PATTERN = "SELECT * FROM resource WHERE %s"; 8 | 9 | private final Query evaluationQuery; 10 | private final String alias; 11 | 12 | public QueryReturnConditional(Query query, String originalValue, String value, String alias) { 13 | super(query, originalValue, value); 14 | this.evaluationQuery = Query.compile(String.format(QUERY_PATTERN, originalValue)); 15 | this.alias = alias; 16 | } 17 | 18 | /** 19 | * Return query instance that contains all the evaluators. 20 | * @return Query evaluation instance. 21 | */ 22 | public Query getEvaluationQuery() { 23 | return evaluationQuery; 24 | } 25 | 26 | /** 27 | * Verify if the query parameter make reference to the specified resource. 28 | * This implementation always returns false because is only for return parameters. 29 | * @param resource Resource instance to test. 30 | * @return Returns true if the parameter make reference to the specified resource and false in the otherwise. 31 | */ 32 | @Override 33 | public boolean verifyResource(QueryResource resource) { 34 | return false; 35 | } 36 | 37 | /** 38 | * Return the field alias, can be null. 39 | * 40 | * @return Field alias. 41 | */ 42 | @Override 43 | public String getAlias() { 44 | return alias; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/http2/frames/GoAwayFrame.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.http2.frames; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | public class GoAwayFrame extends Http2Frame { 6 | 7 | private Integer lastStreamId; 8 | private Integer errorCode; 9 | private String additionalDebugData; 10 | 11 | public GoAwayFrame(Integer id, Byte flags, Integer length) { 12 | super(id, flags, length, Type.GO_AWAY); 13 | } 14 | 15 | public Integer getLastStreamId() { 16 | return lastStreamId; 17 | } 18 | 19 | public void setLastStreamId(Integer lastStreamId) { 20 | this.lastStreamId = lastStreamId; 21 | } 22 | 23 | public Integer getErrorCode() { 24 | return errorCode; 25 | } 26 | 27 | public void setErrorCode(Integer errorCode) { 28 | this.errorCode = errorCode; 29 | } 30 | 31 | public String getAdditionalDebugData() { 32 | return additionalDebugData; 33 | } 34 | 35 | public void setAdditionalDebugData(String additionalDebugData) { 36 | this.additionalDebugData = additionalDebugData; 37 | } 38 | 39 | @Override 40 | protected Integer recalculateLength() { 41 | return null; 42 | } 43 | 44 | @Override 45 | protected void processPayload() { 46 | setLastStreamId(getPayload().getInt()); 47 | setErrorCode(getPayload().getInt()); 48 | byte[] debugData = new byte[getLength() - 8]; 49 | getPayload().get(debugData); 50 | setAdditionalDebugData(new String(debugData)); 51 | } 52 | 53 | @Override 54 | protected ByteBuffer serializePayload(ByteBuffer fixedBuffer) { 55 | return null; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/utils/TtlCollection.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.utils; 2 | 3 | import java.util.HashMap; 4 | import java.util.Iterator; 5 | import java.util.Map; 6 | 7 | /** 8 | * This class provides the mechanism to maintains the wrapped collection 9 | * elements into the collection some time. 10 | * @author javaito 11 | */ 12 | public abstract class TtlCollection { 13 | 14 | private final Map timeWindows; 15 | private final Long timeWindowsSize; 16 | 17 | public TtlCollection(Long timeWindowsSize) { 18 | this.timeWindowsSize = timeWindowsSize; 19 | this.timeWindows = new HashMap<>(); 20 | } 21 | 22 | /** 23 | * Add instance into the ttl map. 24 | * @param instance Instance to add. 25 | */ 26 | protected final synchronized void addInstance(K instance) { 27 | timeWindows.put(System.currentTimeMillis(), instance); 28 | } 29 | 30 | /** 31 | * Removes all the old elements of the wrapped collection. 32 | */ 33 | protected final synchronized void removeOldWindows() { 34 | Long current = System.currentTimeMillis(); 35 | for(Iterator iterator = timeWindows.keySet().iterator(); iterator.hasNext();) { 36 | Long time = iterator.next(); 37 | if((time + timeWindowsSize) < current) { 38 | removeOldInstance(timeWindows.get(time)); 39 | iterator.remove(); 40 | } 41 | } 42 | } 43 | 44 | /** 45 | * This implementation remove the specific instance of the wrapped collection. 46 | * @param instanceKey Instance key. 47 | */ 48 | protected abstract void removeOldInstance(K instanceKey); 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/layers/cache/MapCache.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.cache; 2 | 3 | import org.hcjf.layers.Layer; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class MapCache extends Layer implements CacheLayerInterface> { 9 | 10 | private Map value; 11 | 12 | @Override 13 | public String getImplName() { 14 | return "map"; 15 | } 16 | 17 | /** 18 | * This method invalidate the values into cache and restore its using the datasource associated to the cache. 19 | */ 20 | @Override 21 | public void invalidate() { 22 | value = new HashMap<>(Source.getInstance().getSource()); 23 | } 24 | 25 | /** 26 | * Returns the timeout value, this value indicates the time that the cache is valid. 27 | * 28 | * @return Timeout value. 29 | */ 30 | @Override 31 | public Long timout() { 32 | return 5000L; 33 | } 34 | 35 | /** 36 | * This method returns a current values of the cache. 37 | * 38 | * @return Current value of the cache. 39 | */ 40 | @Override 41 | public Map get() { 42 | return value; 43 | } 44 | 45 | public static final class Source { 46 | 47 | private static final Source instance = new Source(); 48 | private Map source; 49 | 50 | private Source() { 51 | this.source = new HashMap<>(); 52 | } 53 | 54 | public static final Source getInstance() { 55 | return instance; 56 | } 57 | 58 | public Map getSource() { 59 | return source; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/io/net/http/Http2Test.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http; 2 | 3 | import org.hcjf.properties.SystemProperties; 4 | 5 | /** 6 | * @author Javier Quiroga. 7 | * @email javier.quiroga@sitrack.com 8 | */ 9 | public class Http2Test { 10 | 11 | public static void main(String[] args) { 12 | System.setProperty(SystemProperties.Log.SYSTEM_OUT_ENABLED, "true"); 13 | System.setProperty(SystemProperties.Log.TRUNCATE_TAG, "true"); 14 | System.setProperty(SystemProperties.Net.Http.DEFAULT_CLIENT_READ_TIMEOUT, "60000"); 15 | System.setProperty(SystemProperties.Service.THREAD_POOL_CORE_SIZE, "100"); 16 | System.setProperty(SystemProperties.Service.THREAD_POOL_MAX_SIZE, "2000"); 17 | 18 | try { 19 | HttpServer server = new HttpServer(8081); 20 | server.addContext(new Context(".*") { 21 | @Override 22 | public HttpResponse onContext(HttpRequest request) { 23 | byte[] body = "Hola mundo!".getBytes(); 24 | 25 | HttpResponse response = new HttpResponse(); 26 | response.setResponseCode(200); 27 | response.setReasonPhrase("OK"); 28 | response.addHeader(new HttpHeader(HttpHeader.CONTENT_TYPE, "text/plain")); 29 | response.addHeader(new HttpHeader(HttpHeader.CONTENT_LENGTH, Integer.toString(body.length))); 30 | response.setBody(body); 31 | 32 | return response; 33 | } 34 | }); 35 | server.start(); 36 | } catch (Exception ex){ 37 | ex.printStackTrace(); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/network/CloudClient.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.network; 2 | 3 | import org.hcjf.cloud.impl.messages.ShutdownMessage; 4 | import org.hcjf.io.net.NetPackage; 5 | import org.hcjf.io.net.NetSession; 6 | import org.hcjf.io.net.messages.Message; 7 | import org.hcjf.io.net.messages.MessageBuffer; 8 | import org.hcjf.io.net.messages.MessagesNode; 9 | 10 | /** 11 | * @author javaito 12 | */ 13 | public class CloudClient extends MessagesNode { 14 | 15 | private final CloudSession session; 16 | 17 | public CloudClient(String host, Integer port) { 18 | super(host, port); 19 | this.session = new CloudSession(this); 20 | } 21 | 22 | @Override 23 | public CloudSession getSession() { 24 | return session; 25 | } 26 | 27 | @Override 28 | public CloudSession checkSession(CloudSession session, MessageBuffer payLoad, NetPackage netPackage) { 29 | return session; 30 | } 31 | 32 | public void disconnect() { 33 | disconnect(session, ""); 34 | } 35 | 36 | @Override 37 | public void destroySession(NetSession session) { 38 | } 39 | 40 | @Override 41 | protected MessageBuffer getShutdownPackage(CloudSession session) { 42 | MessageBuffer messageBuffer = new MessageBuffer(); 43 | messageBuffer.append(new ShutdownMessage(session)); 44 | return messageBuffer; 45 | } 46 | 47 | @Override 48 | protected void onRead(CloudSession session, Message message) { 49 | CloudOrchestrator.getInstance().incomingMessage(session, message); 50 | } 51 | 52 | @Override 53 | protected void onDisconnect(CloudSession session, NetPackage netPackage) { 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/io/process/ProcessServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.process; 2 | 3 | /** 4 | * @author Javier Quiroga. 5 | * @email javier.quiroga@sitrack.com 6 | */ 7 | public class ProcessServiceTest { 8 | 9 | public static void main(String[] args) { 10 | ProcessDiscoveryService.getInstance().registerConsumer(new ProcessDiscoveryConsumer() { 11 | @Override 12 | public Boolean match(ProcessHandle processHandle) { 13 | boolean result = false; 14 | // if(processHandle.info().command().isPresent()) { 15 | // if(processHandle.info().command().get().endsWith("java")) { 16 | // if(processHandle.info().arguments().isPresent()) { 17 | // if(Arrays.stream(processHandle.info().arguments().get()).anyMatch(S -> S.equals("-classpath"))) { 18 | // result = true; 19 | // } 20 | // } 21 | // } 22 | // } 23 | if(processHandle.info().command().isPresent()) { 24 | if(processHandle.info().command().get().contains("tail")) { 25 | result = true; 26 | } 27 | } 28 | return result; 29 | } 30 | 31 | @Override 32 | public void onDiscovery(ProcessHandle processHandle) { 33 | System.out.println("Discovered: " + processHandle.info().commandLine()); 34 | } 35 | 36 | @Override 37 | public void onKill(ProcessHandle processHandle) { 38 | System.out.println("Killed: " + processHandle.info().commandLine()); 39 | } 40 | }); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/model/QueryReturnUnprocessedValue.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.model; 2 | 3 | import org.hcjf.layers.query.Query; 4 | import org.hcjf.layers.query.evaluators.BaseEvaluator; 5 | 6 | public class QueryReturnUnprocessedValue extends QueryParameter implements QueryReturnParameter { 7 | 8 | private final String alias; 9 | private final BaseEvaluator.UnprocessedValue unprocessedValue; 10 | 11 | public QueryReturnUnprocessedValue(Query query, String originalValue, String alias, BaseEvaluator.UnprocessedValue unprocessedValue) { 12 | super(query, originalValue, "resultSet"); 13 | this.alias = alias; 14 | this.unprocessedValue = unprocessedValue; 15 | } 16 | 17 | /** 18 | * Return the field alias, can be null. 19 | * @return Field alias. 20 | */ 21 | @Override 22 | public String getAlias() { 23 | return alias; 24 | } 25 | 26 | /** 27 | * Returns the unprocessed value instance. 28 | * @return Unprocessed value instance. 29 | */ 30 | public final BaseEvaluator.UnprocessedValue getUnprocessedValue() { 31 | return unprocessedValue; 32 | } 33 | 34 | /** 35 | * Verify if the component is underlying. 36 | * @return True if the component is underlying. 37 | */ 38 | @Override 39 | public boolean isUnderlying() { 40 | return false; 41 | } 42 | 43 | /** 44 | * Verify if the query parameter make reference to the specified resource. 45 | * 46 | * @param resource Resource instance to test. 47 | * @return Returns true if the parameter make reference to the specified resource and false in the otherwise. 48 | */ 49 | @Override 50 | public boolean verifyResource(QueryResource resource) { 51 | return true; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/messages/LayerInvokeMessage.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.messages; 2 | 3 | import org.hcjf.io.net.messages.Message; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public class LayerInvokeMessage extends Message { 11 | 12 | private String className; 13 | private String layerName; 14 | private Object[] path; 15 | private String methodName; 16 | private Class[] parameterTypes; 17 | private Object[] parameters; 18 | 19 | public LayerInvokeMessage() { 20 | } 21 | 22 | public LayerInvokeMessage(UUID id) { 23 | super(id); 24 | } 25 | 26 | public String getClassName() { 27 | return className; 28 | } 29 | 30 | public void setClassName(String className) { 31 | this.className = className; 32 | } 33 | 34 | public String getLayerName() { 35 | return layerName; 36 | } 37 | 38 | public void setLayerName(String layerName) { 39 | this.layerName = layerName; 40 | } 41 | 42 | public Object[] getPath() { 43 | return path; 44 | } 45 | 46 | public void setPath(Object[] path) { 47 | this.path = path; 48 | } 49 | 50 | public String getMethodName() { 51 | return methodName; 52 | } 53 | 54 | public void setMethodName(String methodName) { 55 | this.methodName = methodName; 56 | } 57 | 58 | public Class[] getParameterTypes() { 59 | return parameterTypes; 60 | } 61 | 62 | public void setParameterTypes(Class[] parameterTypes) { 63 | this.parameterTypes = parameterTypes; 64 | } 65 | 66 | public Object[] getParameters() { 67 | return parameters; 68 | } 69 | 70 | public void setParameters(Object[] parameters) { 71 | this.parameters = parameters; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/org/hcjf/layers/cache/Main.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.cache; 2 | 3 | import org.hcjf.layers.Layers; 4 | import org.hcjf.properties.SystemProperties; 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | 10 | System.setProperty(SystemProperties.Log.SYSTEM_OUT_ENABLED, "false"); 11 | 12 | Layers.publishLayer(MapCache.class); 13 | Layers.publishLayer(SubLayerCache.class); 14 | Layers.publishLayer(SubLayerCache2.class); 15 | 16 | CacheServiceConsumer cacheServiceConsumer = new CacheServiceConsumer("subLayer"); 17 | CacheService.getInstance().registerConsumer(cacheServiceConsumer); 18 | CacheServiceConsumer cacheServiceConsumer2 = new CacheServiceConsumer("subLayer2"); 19 | CacheService.getInstance().registerConsumer(cacheServiceConsumer2); 20 | 21 | System.out.println(cacheServiceConsumer.get().toString()); 22 | System.out.println(cacheServiceConsumer2.get().toString()); 23 | 24 | MapCache.Source.getInstance().getSource().put("Key", "value"); 25 | System.out.println(cacheServiceConsumer.get().toString()); 26 | System.out.println(cacheServiceConsumer2.get().toString()); 27 | 28 | try { 29 | Thread.sleep(5000); 30 | } catch (InterruptedException e) { 31 | e.printStackTrace(); 32 | } 33 | 34 | System.out.println(cacheServiceConsumer.get().toString()); 35 | System.out.println(cacheServiceConsumer2.get().toString()); 36 | 37 | try { 38 | Thread.sleep(15000); 39 | } catch (InterruptedException e) { 40 | e.printStackTrace(); 41 | } 42 | 43 | System.out.println(cacheServiceConsumer.get().toString()); 44 | System.out.println(cacheServiceConsumer2.get().toString()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/AddAggregateFunction.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.errors.HCJFRuntimeException; 4 | import org.hcjf.utils.Introspection; 5 | 6 | import java.util.Collection; 7 | 8 | public class AddAggregateFunction extends BaseQueryAggregateFunctionLayer { 9 | 10 | private static final String NAME = "add"; 11 | 12 | public AddAggregateFunction() { 13 | super(NAME); 14 | } 15 | 16 | /** 17 | * Evaluates the specific function. 18 | * @param alias Alias of the function 19 | * @param resultSet Result set obtained for the query evaluation. 20 | * @param parameters Function's parameters. 21 | * @return Function result. 22 | */ 23 | @Override 24 | public Collection evaluate(String alias, Collection resultSet, Object... parameters) { 25 | Collection result = resultSet; 26 | if(parameters.length == 2) { 27 | try { 28 | for(Object row : resultSet) { 29 | String path = resolveValue(row, parameters[0]); 30 | Object value = resolveValue(row, parameters[1]); 31 | if(value instanceof Collection) { 32 | Collection collectionValue = (Collection) value; 33 | Introspection.resolveAndAdd(row, path, collectionValue); 34 | } else { 35 | Introspection.resolveAndAdd(row, path, value); 36 | } 37 | 38 | } 39 | } catch (Exception ex){ 40 | throw new HCJFRuntimeException("Min aggregate function fail", ex); 41 | } 42 | } else { 43 | throw new HCJFRuntimeException("Min aggregate function need at leas two parameters"); 44 | } 45 | return result; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/datasources/DataSourceServiceConsumer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.datasources; 2 | 3 | import org.hcjf.errors.HCJFRuntimeException; 4 | import org.hcjf.layers.query.Queryable; 5 | import org.hcjf.service.ServiceConsumer; 6 | 7 | import java.util.Map; 8 | 9 | public class DataSourceServiceConsumer implements ServiceConsumer { 10 | 11 | private final Map rawDataSources; 12 | private final Queryable.DataSource dataSource; 13 | private Map result; 14 | private Throwable throwable; 15 | 16 | public DataSourceServiceConsumer(Map rawDataSources) { 17 | this(rawDataSources, null); 18 | } 19 | 20 | public DataSourceServiceConsumer(Map rawDataSources, Queryable.DataSource dataSource) { 21 | this.rawDataSources = rawDataSources; 22 | this.dataSource = dataSource; 23 | } 24 | 25 | public Map getRawDataSources() { 26 | return rawDataSources; 27 | } 28 | 29 | public Queryable.DataSource getDataSource() { 30 | return dataSource; 31 | } 32 | 33 | public synchronized void setThrowable(Throwable throwable) { 34 | this.throwable = throwable; 35 | this.notifyAll(); 36 | } 37 | 38 | public synchronized void setResult(Map result) { 39 | this.result = result; 40 | this.notifyAll(); 41 | } 42 | 43 | public synchronized Map getResult() { 44 | if(result == null && throwable == null) { 45 | try { 46 | this.wait(); 47 | } catch (InterruptedException e) { 48 | } 49 | } 50 | 51 | if(throwable != null){ 52 | throw new HCJFRuntimeException("Get data source fail", throwable); 53 | } 54 | 55 | return result; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/LayerProxy.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | /** 6 | * This class wrap the layer invocation with two method, one 7 | * before the invocation and other after invocation. 8 | * @author javaito 9 | * 10 | */ 11 | public interface LayerProxy { 12 | 13 | /** 14 | * This method is called before of layer invocation. 15 | * @param method Layer's method to invoke. 16 | * @param params Parameter's method. 17 | * @return Proxy interceptor instance. 18 | */ 19 | ProxyInterceptor onBeforeInvoke(Method method, Object... params); 20 | 21 | /** 22 | * This method is called after of layer invocation. 23 | * @param method Layer's method to invoke. 24 | * @param result Layer's invocation result. 25 | * @param params Parameter's method. 26 | */ 27 | void onAfterInvoke(Method method, Object result, Object... params); 28 | 29 | /** 30 | * This class is the result of the before invoke method. 31 | */ 32 | class ProxyInterceptor { 33 | 34 | private final boolean cached; 35 | private final Object result; 36 | 37 | public ProxyInterceptor(boolean cached, Object result) { 38 | this.cached = cached; 39 | this.result = result; 40 | } 41 | 42 | public ProxyInterceptor() { 43 | this(false, null); 44 | } 45 | 46 | /** 47 | * Return true if the proxy intercepts the invocation. 48 | * @return Intercept value. 49 | */ 50 | public boolean isCached() { 51 | return cached; 52 | } 53 | 54 | /** 55 | * Return the intercepted value. 56 | * @return Intercepted value. 57 | */ 58 | public Object getResult() { 59 | return result; 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/kubernetes/artifacts/KubernetesJobResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.kubernetes.artifacts; 2 | 3 | import io.kubernetes.client.openapi.models.V1Job; 4 | import org.hcjf.errors.HCJFRuntimeException; 5 | 6 | import java.util.Map; 7 | 8 | public class KubernetesJobResource extends KubernetesArtifactResource { 9 | 10 | public static final String NAME = "system_k8s_job"; 11 | 12 | @Override 13 | public String getImplName() { 14 | return NAME; 15 | } 16 | 17 | @Override 18 | protected Class getArtifactType() { 19 | return V1Job.class; 20 | } 21 | 22 | @Override 23 | protected void createArtifact(V1Job artifact, String pretty, String dryRun, String fieldManager, String fieldValidation) { 24 | try { 25 | getBatchApi().createNamespacedJob(getNamespace(), artifact, pretty, dryRun, fieldManager, fieldValidation); 26 | } catch (Exception ex) { 27 | throw new HCJFRuntimeException("K8s job creation fail", ex); 28 | } 29 | } 30 | 31 | @Override 32 | protected void updateArtifact(String name, V1Job artifact, String pretty, String dryRun, String fieldManager, String fieldValidation) { 33 | try { 34 | getBatchApi().replaceNamespacedJob(name, getNamespace(), artifact, pretty, dryRun, fieldManager, fieldValidation); 35 | } catch (Exception ex) { 36 | throw new HCJFRuntimeException("K8s job creation fail", ex); 37 | } 38 | } 39 | 40 | @Override 41 | protected boolean isCreated(String manifestName) { 42 | boolean result = false; 43 | try { 44 | V1Job job = getBatchApi().readNamespacedJob(manifestName, getNamespace(), null); 45 | if (job != null){ 46 | result = true; 47 | } 48 | } catch (Exception ex) {} 49 | return result; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/cloud/impl/network/DistributedLayerRegistry.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.cloud.impl.network; 2 | 3 | import java.util.UUID; 4 | 5 | public class DistributedLayerRegistry { 6 | 7 | public static final class Protocol { 8 | public static final String HCM = "HCM"; 9 | public static final String HTTP = "HTTP"; 10 | } 11 | 12 | private UUID id; 13 | private String className; 14 | private String layerName; 15 | private UUID serviceEndPoint; 16 | private String regex; 17 | private String protocol; 18 | 19 | public UUID getId() { 20 | return id; 21 | } 22 | 23 | public void setId(UUID id) { 24 | this.id = id; 25 | } 26 | 27 | public String getClassName() { 28 | return className; 29 | } 30 | 31 | public void setClassName(String className) { 32 | this.className = className; 33 | } 34 | 35 | public String getLayerName() { 36 | return layerName; 37 | } 38 | 39 | public void setLayerName(String layerName) { 40 | this.layerName = layerName; 41 | } 42 | 43 | public UUID getServiceEndPoint() { 44 | return serviceEndPoint; 45 | } 46 | 47 | public void setServiceEndPoint(UUID serviceEndPoint) { 48 | this.serviceEndPoint = serviceEndPoint; 49 | } 50 | 51 | public String getRegex() { 52 | return regex; 53 | } 54 | 55 | public void setRegex(String regex) { 56 | this.regex = regex; 57 | } 58 | 59 | public String getProtocol() { 60 | return protocol; 61 | } 62 | 63 | public void setProtocol(String protocol) { 64 | this.protocol = protocol; 65 | } 66 | 67 | public static UUID createDistributedLayerId(String className, String layerName) { 68 | return new UUID(className.hashCode(), layerName.hashCode()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/CountQueryAggregateFunctionLayer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.errors.HCJFRuntimeException; 4 | import org.hcjf.layers.query.Enlarged; 5 | import org.hcjf.layers.query.JoinableMap; 6 | import org.hcjf.utils.Strings; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Collection; 10 | import java.util.HashMap; 11 | 12 | /** 13 | * @author javaito 14 | */ 15 | public class CountQueryAggregateFunctionLayer extends BaseQueryAggregateFunctionLayer { 16 | 17 | private static final String NAME = "count"; 18 | 19 | public CountQueryAggregateFunctionLayer() { 20 | super(NAME); 21 | } 22 | 23 | @Override 24 | public Collection evaluate(String alias, Collection resultSet, Object... parameters) { 25 | Collection result = resultSet; 26 | if(parameters.length == 0 || parameters[0].equals(Strings.ALL)) { 27 | Collection newResultSet = new ArrayList<>(); 28 | JoinableMap size = new JoinableMap(new HashMap<>(), alias); 29 | size.put(alias, resultSet.size()); 30 | newResultSet.add(size); 31 | result = newResultSet; 32 | } else { 33 | try { 34 | Object value; 35 | Integer countValue; 36 | for (Object row : resultSet) { 37 | value = resolveValue(row, parameters[0]); 38 | if(value instanceof Collection) { 39 | countValue = ((Collection)value).size(); 40 | } else { 41 | countValue = 1; 42 | } 43 | ((Enlarged)row).put(alias, countValue); 44 | } 45 | } catch (Exception ex){ 46 | throw new HCJFRuntimeException("Count aggregate function fail", ex); 47 | } 48 | } 49 | return result; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/query/functions/PutAggregateFunction.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.query.functions; 2 | 3 | import org.hcjf.errors.HCJFRuntimeException; 4 | import org.hcjf.utils.Introspection; 5 | 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | public class PutAggregateFunction extends BaseQueryAggregateFunctionLayer { 10 | 11 | private static final String NAME = "put"; 12 | 13 | public PutAggregateFunction() { 14 | super(NAME); 15 | } 16 | 17 | /** 18 | * Evaluates the specific function. 19 | * @param alias Alias of the function 20 | * @param resultSet Result set obtained for the query evaluation. 21 | * @param parameters Function's parameters. 22 | * @return Function result. 23 | */ 24 | @Override 25 | public Collection evaluate(String alias, Collection resultSet, Object... parameters) { 26 | Collection result = resultSet; 27 | if(parameters.length >= 2) { 28 | try { 29 | for(Object row : resultSet) { 30 | String path = resolveValue(row, parameters[0]); 31 | if(parameters.length == 3) { 32 | String key = resolveValue(row, parameters[1]); 33 | Object value = resolveValue(row, parameters[2]); 34 | Introspection.resolveAndPut(row, path, key, value); 35 | } else { 36 | Map values = resolveValue(row, parameters[1]); 37 | Introspection.resolveAndPutAll(row, path, values); 38 | } 39 | } 40 | } catch (Exception ex){ 41 | throw new HCJFRuntimeException("Put aggregate function fail", ex); 42 | } 43 | } else { 44 | throw new HCJFRuntimeException("Put aggregate function need at leas two parameters"); 45 | } 46 | return result; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/Cookie2.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http; 2 | 3 | import org.hcjf.utils.Strings; 4 | 5 | /** 6 | * @author javaito 7 | */ 8 | public class Cookie2 extends Cookie { 9 | 10 | public static final String COMMENT_URL = "CommentURL"; 11 | public static final String PORT = "PORT"; 12 | public static final String DISCARD = "Discard"; 13 | 14 | private String commentUrl; 15 | private Integer port; 16 | private boolean discard; 17 | 18 | public Cookie2(String name, String value) { 19 | super(name, value); 20 | } 21 | 22 | public String getCommentUrl() { 23 | return commentUrl; 24 | } 25 | 26 | public void setCommentUrl(String commentUrl) { 27 | this.commentUrl = commentUrl; 28 | } 29 | 30 | public Integer getPort() { 31 | return port; 32 | } 33 | 34 | public void setPort(Integer port) { 35 | this.port = port; 36 | } 37 | 38 | public boolean isDiscard() { 39 | return discard; 40 | } 41 | 42 | public void setDiscard(boolean discard) { 43 | this.discard = discard; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | Strings.Builder result = new Strings.Builder(); 49 | result.append(super.toString()); 50 | 51 | if(getCommentUrl() != null) { 52 | result.append(Strings.ARGUMENT_SEPARATOR_2).append(Strings.WHITE_SPACE); 53 | result.append(COMMENT_URL).append(Strings.ASSIGNATION).append(getCommentUrl()); 54 | } 55 | 56 | if(getPort() != null) { 57 | result.append(Strings.ARGUMENT_SEPARATOR_2).append(Strings.WHITE_SPACE); 58 | result.append(PORT).append(Strings.ASSIGNATION).append(getPort()); 59 | } 60 | 61 | if(isDiscard()) { 62 | result.append(Strings.ARGUMENT_SEPARATOR_2).append(Strings.WHITE_SPACE); 63 | result.append(DISCARD); 64 | } 65 | 66 | return result.toString(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/kubernetes/artifacts/KubernetesDeploymentResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.kubernetes.artifacts; 2 | 3 | import io.kubernetes.client.openapi.models.V1Deployment; 4 | import org.hcjf.errors.HCJFRuntimeException; 5 | import java.util.Map; 6 | 7 | public class KubernetesDeploymentResource extends KubernetesArtifactResource { 8 | 9 | public static final String NAME = "system_k8s_deployment"; 10 | 11 | @Override 12 | public String getImplName() { 13 | return NAME; 14 | } 15 | 16 | @Override 17 | protected Class getArtifactType() { 18 | return V1Deployment.class; 19 | } 20 | 21 | @Override 22 | protected void createArtifact(V1Deployment artifact, String pretty, String dryRun, String fieldManager, String fieldValidation) { 23 | try { 24 | getAppsApi().createNamespacedDeployment(getNamespace(), artifact, pretty, dryRun, fieldManager, fieldValidation); 25 | } catch (Exception ex) { 26 | throw new HCJFRuntimeException("K8s deployment creation fail", ex); 27 | } 28 | } 29 | 30 | @Override 31 | protected void updateArtifact(String name, V1Deployment artifact, String pretty, String dryRun, String fieldManager, String fieldValidation) { 32 | try { 33 | getAppsApi().replaceNamespacedDeployment(name, getNamespace(), artifact, pretty, dryRun, fieldManager, fieldValidation); 34 | } catch (Exception ex) { 35 | throw new HCJFRuntimeException("K8s deployment creation fail", ex); 36 | } 37 | } 38 | 39 | @Override 40 | protected boolean isCreated(String manifestName) { 41 | boolean result = false; 42 | try { 43 | V1Deployment deployment = getAppsApi().readNamespacedDeployment(manifestName, getNamespace(), null); 44 | if (deployment != null){ 45 | result = true; 46 | } 47 | } catch (Exception ex) {} 48 | return result; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/kubernetes/artifacts/KubernetesCronJobResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.kubernetes.artifacts; 2 | 3 | import io.kubernetes.client.openapi.models.V1CronJob; 4 | import org.hcjf.errors.HCJFRuntimeException; 5 | import org.hcjf.utils.Introspection; 6 | 7 | import java.util.Map; 8 | 9 | public class KubernetesCronJobResource extends KubernetesArtifactResource { 10 | 11 | public static final String NAME = "system_k8s_cron_job"; 12 | 13 | @Override 14 | public String getImplName() { 15 | return NAME; 16 | } 17 | 18 | @Override 19 | protected Class getArtifactType() { 20 | return V1CronJob.class; 21 | } 22 | 23 | @Override 24 | protected void createArtifact(V1CronJob artifact, String pretty, String dryRun, String fieldManager, String fieldValidation) { 25 | try { 26 | getBatchApi().createNamespacedCronJob(getNamespace(), artifact, pretty, dryRun, fieldManager, fieldValidation); 27 | } catch (Exception ex) { 28 | throw new HCJFRuntimeException("K8s cron job creation fail", ex); 29 | } 30 | } 31 | 32 | @Override 33 | protected void updateArtifact(String name, V1CronJob artifact, String pretty, String dryRun, String fieldManager, String fieldValidation) { 34 | try { 35 | getBatchApi().replaceNamespacedCronJob(name,getNamespace(), artifact, pretty, dryRun, fieldManager, fieldValidation); 36 | } catch (Exception ex) { 37 | throw new HCJFRuntimeException("K8s cron job creation fail", ex); 38 | } 39 | } 40 | 41 | @Override 42 | protected boolean isCreated(String manifestName) { 43 | boolean result = false; 44 | try { 45 | V1CronJob cronJob = getBatchApi().readNamespacedCronJob(manifestName, getNamespace(), null); 46 | if (cronJob != null){ 47 | result = true; 48 | } 49 | } catch (Exception ex) {} 50 | return result; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/http/pipeline/MultipartHttpPipelineResponse.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.http.pipeline; 2 | 3 | import org.hcjf.io.net.http.HttpHeader; 4 | 5 | import java.nio.ByteBuffer; 6 | 7 | /** 8 | * @author javaito 9 | */ 10 | public abstract class MultipartHttpPipelineResponse extends HttpPipelineResponse { 11 | 12 | private static final byte[] END = "--".getBytes(); 13 | private static final byte[] MULTIPART_BOUNDARY_START = "\r\n--".getBytes(); 14 | private static final byte[] HEADER_SEPARATOR = "\r\n".getBytes(); 15 | 16 | private final String boundary; 17 | private boolean end; 18 | 19 | public MultipartHttpPipelineResponse(int mainBufferSize, int bufferSize, String boundary) { 20 | super(mainBufferSize, bufferSize); 21 | this.boundary = boundary; 22 | } 23 | 24 | @Override 25 | protected int wrap(ByteBuffer result, StreamingPackage streamingPackage, int size) { 26 | int resultSize; 27 | if(size == -1 && end) { 28 | resultSize = -1; 29 | } else { 30 | result.put(MULTIPART_BOUNDARY_START); 31 | result.put(boundary.getBytes()); 32 | result.put(HEADER_SEPARATOR); 33 | if(streamingPackage.contains(HttpHeader.CONTENT_DISPOSITION)) { 34 | result.put(streamingPackage.get(HttpHeader.CONTENT_DISPOSITION).toString().getBytes()); 35 | result.put(HEADER_SEPARATOR); 36 | } 37 | if(streamingPackage.contains(HttpHeader.CONTENT_TYPE)) { 38 | result.put(streamingPackage.get(HttpHeader.CONTENT_TYPE).toString().getBytes()); 39 | result.put(HEADER_SEPARATOR); 40 | } 41 | if(size == -1) { 42 | end = true; 43 | result.put(END); 44 | } else { 45 | result.put(streamingPackage.getBuffer(), 0, size); 46 | } 47 | resultSize = result.position(); 48 | } 49 | 50 | return resultSize; 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/kubernetes/artifacts/KubernetesServiceResource.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.kubernetes.artifacts; 2 | 3 | import org.hcjf.errors.HCJFRuntimeException; 4 | 5 | import io.kubernetes.client.openapi.models.V1Service; 6 | 7 | public class KubernetesServiceResource extends KubernetesArtifactResource { 8 | 9 | public static final String NAME = "system_k8s_service"; 10 | 11 | @Override 12 | public String getImplName() { 13 | return NAME; 14 | } 15 | 16 | @Override 17 | protected Class getArtifactType() { 18 | return V1Service.class; 19 | } 20 | 21 | 22 | @Override 23 | protected void createArtifact(V1Service artifact, String pretty, String dryRun, String fieldManager, 24 | String fieldValidation) { 25 | try { 26 | getCoreApi().createNamespacedService(getNamespace(), artifact, pretty, dryRun, fieldManager, 27 | fieldValidation); 28 | } catch (Exception ex) { 29 | throw new HCJFRuntimeException("K8s service creation fail", ex); 30 | } 31 | } 32 | 33 | @Override 34 | protected void updateArtifact(String name, V1Service artifact, String pretty, String dryRun, String fieldManager, 35 | String fieldValidation) { 36 | try { 37 | getCoreApi().replaceNamespacedService(name, getNamespace(), artifact, pretty, dryRun, fieldManager, 38 | fieldValidation); 39 | } catch (Exception ex) { 40 | throw new HCJFRuntimeException("K8s service creation fail", ex); 41 | } 42 | } 43 | 44 | @Override 45 | protected boolean isCreated(String manifestName) { 46 | boolean result = false; 47 | try { 48 | V1Service service = getCoreApi().readNamespacedService(manifestName, getNamespace(), null); 49 | if (service != null) { 50 | result = true; 51 | } 52 | } catch (Exception ex) { 53 | } 54 | return result; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/net/broadcast/BroadcastConsumer.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.net.broadcast; 2 | 3 | import org.hcjf.service.ServiceConsumer; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * This interface provides all the methods as needed to register a broadcast consumer. 9 | * @author javaito 10 | */ 11 | public interface BroadcastConsumer extends ServiceConsumer { 12 | 13 | /** 14 | * Returns the name of the task. 15 | * @return Task name. 16 | */ 17 | public String getTaskName(); 18 | 19 | /** 20 | * Returns the private key for the consumer. 21 | * @return Private key. 22 | */ 23 | public String getPrivateKey(); 24 | 25 | /** 26 | * Returns the ip version to 27 | * @return Return the ip version. 28 | */ 29 | public String getIpVersion(); 30 | 31 | /** 32 | * Returns the name of the net interface to broadcast messages. 33 | * @return Net interface name. 34 | */ 35 | public String getNetInterfaceName(); 36 | 37 | /** 38 | * Returns the port to initialize the broadcast server. 39 | * @return Port. 40 | */ 41 | public Integer getPort(); 42 | 43 | /** 44 | * Returns the map with the implementation parameters for the broadcast ping message. 45 | * @return Parameters map. 46 | */ 47 | public Map getPingParameters(); 48 | 49 | /** 50 | * This method is invoked when the instance receive a broadcast ping message. 51 | * @param pingMessage Broadcast ping message. 52 | */ 53 | public void onPing(BroadcastService.PingMessage pingMessage); 54 | 55 | /** 56 | * This method is invoked when the instance receive a broadcast pong message. 57 | * @param pongMessage Broadcast pong message. 58 | */ 59 | public void onPong(BroadcastService.PongMessage pongMessage); 60 | 61 | /** 62 | * This method is invoked when the instance receive a broadcast shutdown massage. 63 | * @param shutdownMessage Broadcast shutdown message. 64 | */ 65 | public void onShutdown(BroadcastService.ShutdownMessage shutdownMessage); 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/io/console/ServerMetadata.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.io.console; 2 | 3 | import org.hcjf.utils.bson.BsonParcelable; 4 | 5 | import java.util.List; 6 | import java.util.UUID; 7 | 8 | /** 9 | * Server metadata model. 10 | * @author javaito 11 | */ 12 | public class ServerMetadata implements BsonParcelable { 13 | 14 | private UUID instanceId; 15 | private String serverName; 16 | private String serverVersion; 17 | private String clusterName; 18 | private Boolean loginRequired; 19 | private List loginFields; 20 | private List loginSecretFields; 21 | 22 | public UUID getInstanceId() { 23 | return instanceId; 24 | } 25 | 26 | public void setInstanceId(UUID instanceId) { 27 | this.instanceId = instanceId; 28 | } 29 | 30 | public String getServerName() { 31 | return serverName; 32 | } 33 | 34 | public void setServerName(String serverName) { 35 | this.serverName = serverName; 36 | } 37 | 38 | public String getServerVersion() { 39 | return serverVersion; 40 | } 41 | 42 | public void setServerVersion(String serverVersion) { 43 | this.serverVersion = serverVersion; 44 | } 45 | 46 | public String getClusterName() { 47 | return clusterName; 48 | } 49 | 50 | public void setClusterName(String clusterName) { 51 | this.clusterName = clusterName; 52 | } 53 | 54 | public Boolean getLoginRequired() { 55 | return loginRequired; 56 | } 57 | 58 | public void setLoginRequired(Boolean loginRequired) { 59 | this.loginRequired = loginRequired; 60 | } 61 | 62 | public List getLoginFields() { 63 | return loginFields; 64 | } 65 | 66 | public void setLoginFields(List loginFields) { 67 | this.loginFields = loginFields; 68 | } 69 | 70 | public List getLoginSecretFields() { 71 | return loginSecretFields; 72 | } 73 | 74 | public void setLoginSecretFields(List loginSecretFields) { 75 | this.loginSecretFields = loginSecretFields; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/hcjf/layers/plugins/Plugin.java: -------------------------------------------------------------------------------- 1 | package org.hcjf.layers.plugins; 2 | 3 | import org.hcjf.layers.Layer; 4 | import org.hcjf.utils.Version; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author javaito 11 | */ 12 | public final class Plugin { 13 | 14 | private final String groupName; 15 | private final String name; 16 | private final Version version; 17 | private final List> layers; 18 | 19 | public Plugin(String groupName, String name, Version version) { 20 | this.groupName = groupName; 21 | this.name = name; 22 | this.version = version; 23 | this.layers = new ArrayList<>(); 24 | } 25 | 26 | /** 27 | * Return the group name. 28 | * @return Group name. 29 | */ 30 | public String getGroupName() { 31 | return groupName; 32 | } 33 | 34 | /** 35 | * Return the plugin name. 36 | * @return Plugin name. 37 | */ 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | /** 43 | * Return the plugin version. 44 | * @return Plugin version. 45 | */ 46 | public Version getVersion() { 47 | return version; 48 | } 49 | 50 | /** 51 | * Add a layer class into the plugin definition. 52 | * @param layerClass Layer class. 53 | */ 54 | public void addLayer(Class layerClass) { 55 | layers.add(layerClass); 56 | } 57 | 58 | /** 59 | * Returns a list of layer definition. 60 | * @return Layers list. 61 | */ 62 | public List> getLayers() { 63 | return layers; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return groupName + ", " + name + ", " + version.toString(); 69 | } 70 | 71 | @Override 72 | public boolean equals(Object obj) { 73 | boolean result = false; 74 | if(obj instanceof Plugin) { 75 | result = groupName.equals(((Plugin)obj).groupName) && name.equals(((Plugin)obj).name); 76 | } 77 | return result; 78 | } 79 | } 80 | --------------------------------------------------------------------------------