Skip to content

Instantly share code, notes, and snippets.

View ahodroj's full-sized avatar

Ali Hodroj ahodroj

View GitHub Profile
<bean id="myFunction" class="AdjustPriceSqlFunction" />
<os-core:embedded-space id="space" name="mySpace">
<os-core:space-sql-function name="ADJUSTED_PRICE">
<os-core:sql-function ref="myFunction" />
</os-core:space-sql-function>
</os-core:embedded-space>
public class AdjustPriceSqlFunction extends SqlFunction {
@Override
public Object apply(SqlFunctionExecutionContext context) {
// Add 20%
return (Double)context.getArgument(0) * 1.2;
}
}
# Start two GSCs, two global GSMs and two global LUSs and a ZooKeeper
gs-agent gsa.gsc 2 gsa.global.gsm 2 gsa.global.lus 2 gsa.zk 1
// A SQL query with a user-defined function ADJUSTED_PRICE
// which will return all the stock prices with an adjusted price = 23.2
query = new SQLQuery<Stock>(Stock.class, "ADJUSTED_PRICE(price) = ?", 23.2);
IntValue[] values = gigaSpace.readMultiple(query);
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:os-core="http://www.openspaces.org/schema/core"
xmlns:blob-store="http://www.openspaces.org/schema/rocksdb-blob-store"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.openspaces.org/schema/core http://www.openspaces.org/schema/11.0/core/openspaces-core.xsd
http://www.openspaces.org/schema/rocksdb-blob-store http://www.openspaces.org/schema/11.0/rocksdb-blob-store/openspaces-rocksdb-blobstore.xsd">
<blob-store:rocksdb-blob-store id="myBlobStore" paths="[/mnt/db1,/mnt/db2]"
import org.openspaces.spatial.shapes.Point;
public class GasStation {
private Point location;
@SpaceSpatialIndex
public Point getLocation() {
return location;
}
@ahodroj
ahodroj / geospatial.java
Last active April 12, 2016 03:49
Sample Geospatial Query in XAP11
public GasStation findNearbyGasStation(Point location, int radius) {
SQLQuery<GasStation> query = new SQLQuery(GasStation.class, "location spatial:within ?")
.setParameter(1, ShapeFactory.circle(location, radius));
return gigaSpace.read(query);
}
@ahodroj
ahodroj / gist:5060718
Last active December 14, 2015 08:49
Starts an elastic in-memory data grid in XAP running with ESM
import org.openspaces.admin.*
import org.openspaces.admin.pu.elastic.config.ManualCapacityScaleConfigurer
import org.openspaces.admin.space.ElasticSpaceDeployment
import org.openspaces.core.util.MemoryUnit
println "Starting Elastic In-Memory Data Grid..."
pu = new AdminFactory().addGroup("ahodroj").createAdmin().gridServiceManagers.waitForAtLeastOne().deploy(
new ElasticSpaceDeployment("mySpace")
.memoryCapacityPerContainer(128, MemoryUnit.MEGABYTES).maxMemoryCapacity(2048, MemoryUnit.MEGABYTES)
.singleMachineDeployment()
@ahodroj
ahodroj / server.js
Created September 6, 2012 19:34
NodeJS Simple Server
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World from Node\n');
}).listen(3383);
console.log('Server running at http://127.0.0.1:3383/');
object/2
invoke/3
::/2
get_property/3
set_property/3