<< December 2016 | Home | February 2017 >>

xText - use custom properties in CustomOutputConfigurationProvider

Ok, that is a very special topic and I guess not many will need this.
My problem was that I created a properties-page and wanted to use the folders selected there or to use IProject-related paths or such. I had to hack a little bit to get it to work, but I did it. In the end I could have context-based CustomOutputConfigurations.

Ok, I got it to work but it feels a bit hacky. Here is what I did.

  1. Write OutputConfigurationProvider that implements IContextualOutputProvider2 and place it somewhere in your MyDSL-Modules main-module
public class CustomOutputConfigurationProvider  implements IContextualOutputConfigurationProvider2 {

	override getOutputConfigurations(ResourceSet context) {
		if (context.resources.size()>0){
			// we are now context-aware. With the resource we can access the project
			val Resource res = context.resources.get(0);
			val path = res.URI.toPlatformString(true);
			val file = ResourcesPlugin.workspace.root.findMember(path) as IFile;
			val IProject project = file.project		
			// do what you want! e.g. read properties (as I intend to do)
			val OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT);
			defaultOutput.setDescription("Default Output - Overwrite");
			defaultOutput.useOutputPerSourceFolder = true;
			return newHashSet(defaultOutput);
		return newHashSet();
  1. Bind it in your MyDSLRuntimeModule:
	def Class<? extends IContextualOutputConfigurationProvider2> bindIContextualOutputConfigurationProvider2() {

3)In the UI-Module create a CustomBuilderParticipant that derives from BuilderPartiticpant:

public class CustomBuilderParticipant extends BuilderParticipant {

	private IContextualOutputConfigurationProvider2 outputConfigurationProvider;
	protected Map<String, OutputConfiguration> getOutputConfigurations(IBuildContext context) {
		Set<OutputConfiguration> configurations = outputConfigurationProvider.getOutputConfigurations(context
		return uniqueIndex(configurations, new Function<OutputConfiguration, String>() {
			public String apply(OutputConfiguration from) {
				return from.getName();
  1. Bind this in your UI-Modules MsDSLUIModule.xtend:
	override Class<? extends IXtextBuilderParticipant> bindIXtextBuilderParticipant() {
		return CustomBuilderParticipant;

That's it. Seems to work. Also have a look at a corresponding forum-thread .

Tags : , ,

Global Game Jam / Düren

It was GlobalGamJam and I decided to give it a shot. It was very attractive since there was a jam-site in Düren where I live. Very small one organized by headup games. (Big thank to them, Mark and Dieter).

Since I do need to get into Unity3d again, that was a perfect oppurtunity to do this. Nothing better than pressure (ok, I assume during the pressure-phase I wouldn't sign that phrase ;) ).

I make it short. I created a simple mixture. A 'zombie survival game' with two modes. One to set traps and the second to lead the player chasing zombies in these traps. There was a spring-trap, some fences to lead them in a direction and a bombtrap which you could fire. As always there was not much time for level-design. But hey, it was ok. Nothing fancy, and nothing that I couldn't have done with gamekit ;)

Here is the thing: About traps and zombies

EDIT: I now really played the game the first time after the jam and I have to say, I do like it! Beside there is some nasty bug that restarts the level from time to time when you jump. Beside this. Nicely done ;)

ZeroMQ - Fun Part II

In this sample:

  • send data directly from target to service1
  • send data from service2 to target and back
package org.tt.zmq.tests;

import org.junit.Test;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;
import org.zeromq.ZMsg;

 * Here I will keep some tests to understand the behaviour of ZMQ-Socket-Types
 * @author dertom95
public class ZMQBTo2Dealers2 {

	private static void doProxy(ZMQ.Socket from, ZMQ.Socket to) {
		ZMsg msg = ZMsg.recvMsg(from);

	public void testBoundRountTo2Dealers() {
		// create one context for each logical section to "simulate" different
		// computers

		// ------------ setup target -----------------------
		ZContext ctxTarget = new ZContext();

		ZMQ.Socket target = ctxTarget.createSocket(ZMQ.ROUTER);
		// give the socket an identity. this name will be used as address if
		// this socket connects to a router.
		// this is important if you want to route to a socket that didn't
		// contact you before

		// ------------ setup proxy -------------------------
		ZContext ctxProxy = new ZContext();

		ZMQ.Socket dealer = ctxProxy.createSocket(ZMQ.DEALER);
		// give the dealer an identity. here it is actually important
		ZMQ.Socket proxy = ctxProxy.createSocket(ZMQ.ROUTER);

		// ----------- setup service ----------------------
		ZContext ctxServices = new ZContext();
		ZMQ.Socket service1 = ctxServices.createSocket(ZMQ.DEALER);
		// give the dealer an identity. here it is actually important

		ZMQ.Socket service2 = ctxServices.createSocket(ZMQ.DEALER);
		// give the dealer an identity. here it is actually important

		// ------------ actions -----------------------------

		// send data from server over the proxy to service1

		// let's create the message and tell which way it should go.
		// 1. go to socket that's identity is 'dealer' on the first
		// router-socket
		// 2. go to socket that's identity is 'service1' on the 2nd
		// router-socket
		// 3. Give it the data and send this to target.
		// target-socket is our start-socket which is a router
		// this will pop the first line of our msg ('dealer') and checks if
		// there
		// is a socket called 'dealer' known to the router. If yes pass the rest
		// of
		// the message (without the 'dealer'-address) to this socket
		target.send("target greets you service1");

		// the target-router should have routed automatically to the
		// 'dealer'-socket
		// so we should be able receive the message
		// the job of the dealer is to get the message and to pass it as it is
		// to the
		// proxy which is a router socket.
		ZMsg dealerIncomingMsg = ZMsg.recvMsg(dealer);
		// check if the routing-address is "service1"
		String dealerIncomingAddress = dealerIncomingMsg.peekFirst().toString();
		assert (dealerIncomingAddress.equals("service1"));
		// send the message as it is to the proxy-router. this will take the
		// first-line as routing-address
		// checks also if this address is known and if yes it will pass the rest
		// of the message automatically to this socket

		// Since service1-socket is connected to proxy-router and has the
		// identiy "service1" it should be able to receive
		// the message now.
		ZMsg service1Incoming = ZMsg.recvMsg(service1);
		String service1IncomingData = service1Incoming.popString();
		assert (service1IncomingData.equals("target greets you service1"));

		// now let's send a message from 'serivce2' to 'target'.
		// send the message to our own socket 'service2' which is connected to
		// proxy
		service2.send("hello target!");

		// therefore the data we send via service2 will end up in the
		// incoming-queue of proxy-socket
		ZMsg proxyIncomingMsg = ZMsg.recvMsg(proxy);
		// receiving(?) on a router-socket adds the address of the socket that
		// sent the message
		// to check the should beside the data there should now be an additional
		// address-line 'service2'
		String service2Address = proxyIncomingMsg.peekFirst().toString();
		assert (service2Address.equals("service2"));
		// send the message without doing something further to our dealer-proxy
		// which is connected to the target
		// therefore sending through 'dealer'-socket should make the message
		// available on target which is a router-socket.

		// receive the message
		ZMsg targetIncomingMsg = ZMsg.recvMsg(target);
		// since target is also a router there should be a 2nd additional
		// address-line that points to the dealer, who sent
		// data from the dealer-socket to this target-socket
		String dealerAddress = targetIncomingMsg.peekFirst().toString();
		assert (dealerAddress.equals("dealer"));

		String data = targetIncomingMsg.getLast().toString();
		System.out.println("Got message from service2:" + data);

		// To send data BACK we can reuse the message
		// 1. get rid of the old data
		// 2. add our new data
		targetIncomingMsg.addLast("Heyho, let's go!");
		// since in this message all routing information were created
		// automatically on the way from service1 to target
		// the message has everything its need to send data back to the caller

		// pass data from dealer to proxy (as we did when send directly from
		// target to service1 at the beginning)
		dealerIncomingMsg = ZMsg.recvMsg(dealer);

		// now we should get the data again on our service2-socket
		ZMsg service2IncomingMsg = ZMsg.recvMsg(service2);
		data = service2IncomingMsg.popString();
		assert (data.equals("Heyho, let's go!"));
		System.out.println("Get some data back from target:" + data);

Tags : , ,

ZeroMQ - Fun Part 1

ZeroMQ - Mindgames and Samples

Router bound, 2 Dealers connected to Router


In this sample:

  • Send data from dealer1 to router
  • Create message to push data from router to dealer1 and dealer2
package org.tt.zmq.tests;

import java.nio.charset.Charset;

import org.junit.Test;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;
import org.zeromq.ZMsg;

public class BRouterToCDealer {

	public void testmain() {
		ZContext ctx = new ZContext();

		ZMQ.Socket router = ctx.createSocket(ZMQ.ROUTER);
		// give the socket an identity. this name will be used as address if
		// this socket connects to a router.
		// this is important if you want to route to a socket that didn't
		// contact you before

		ZMQ.Socket dealer1 = ctx.createSocket(ZMQ.DEALER);
		// give the dealer an identity. here it is actually important

		ZMQ.Socket dealer2 = ctx.createSocket(ZMQ.DEALER);
		// give the dealer an identity. here it is actually important

		// send data to router
		// receive data as msg from router.
		// the router adds one frame with the address of the caller to be able
		// to send it back again
		ZMsg msg = ZMsg.recvMsg(router);
		// get that address that is added by the router
		String addressFromCaller = msg.popString();
		assert (addressFromCaller.equals("dealer1"));
		// get the actual data sent by dealer1
		String dataSentByCaller = msg.popString();
		assert (dataSentByCaller.equals("d1-data"));
		System.out.println("router got msg:" + msg);

		// send data from router to dealer1
		// stack togather:
		// first the address
		// followed by the data that should be sent to dealer1
		// the router gets the whole msg and expects the first frame to be a
		// routing-address
		// if this address is in a internal table it pops the address again and
		// sends the rest to this connection
		router.send("r1 - hi dealer1");

		// you can send as many msgs as you want (and as the router-queue can
		// handle)
		// now let's send a message to dealer2 using ZMsg
		ZMsg msgToD2 = new ZMsg();
		// here we have to stack upwards down.
		// first: the data
		msgToD2.push("r1 - hi dealer2");
		// second: the routing-address

		// now let's receive the msgs the server sent
		msg = ZMsg.recvMsg(dealer1);
		String incomingMsgD1 = msg.popString();
		assert (incomingMsgD1.equals("r1 - hi dealer1"));
		System.out.println("dealer1:" + incomingMsgD1);
		// get the data directly from the socket
		String incomingDataD2 = dealer2.recvStr(Charset.defaultCharset());
		assert (incomingDataD2.equals("r1 - hi dealer2"));
		System.out.println("dealer2:" + incomingDataD2);
		// check if there are more parts left in the msgs we are now reading
		// line by line (in our case,no)
		boolean moreData = dealer2.hasReceiveMore();
		assert (!moreData);

		// close the context
Tags : , ,


Every time fun setting up a maven-project. Here is my minimal default-setup for:

  • an additional src-folder
  • setting up the compiler
  • creating a fat jar via: mvn assembly:once

Tags : , ,

ZeroMQ using Java

Still have in my mind using ZeroMQ as Transport-Layer for my thrift-based communication between Server and Server and Server and Client. Therefore I took a deep look into JZMQ which is the JAVA-JNI Mapping for ZeroMQ. At the beginning I thought that Curve based encryptions wasn't built in yet, but it was only Certificate based authentification that wasn't implemented,yet. And even though I actually don't need to use it, I gave it a try to port it to Java.

This resulted in another pullrequest , let's see if that will be accepted, as this is something else than the former examples that I fixed for czmq. (EDIT: Just saw that travis is complaining about the jUnit-tests I wrote. One seems to keep blocking on OpenJDK6! Argh )

Using this I could port all security examples to java. Here as example the last certificate based authentication:

package org.tt.zmq.security;

import java.nio.charset.Charset;

import org.zeromq.ZAuth;
import org.zeromq.ZCert;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;

//The Ironhouse Pattern
//Security doesn't get any stronger than this. An attacker is going to
//have to break into your systems to see data before/after encryption.
public class Ironhouse {

	private static final String CERTIFICATE_FOLDER=".curve";
	public static void main(String[] args) {
	    //  Create context
		ZContext ctx = new ZContext();
	    //  Start an authentication engine for this context. This engine
	    //  allows or denies incoming connections (talking to the libzmq
	    //  core over a protocol called ZAP).
		ZAuth auth = new ZAuth(ctx);
	    //  Get some indication of what the authenticator is deciding
	    //  Whitelist our address; any other address will be rejected
	    //  Tell authenticator to use the certificate store in .curve

	    //  We'll generate a new client certificate and save the public part
	    //  in the certificate store (in practice this would be done by hand
	    //  or some out-of-band process).
	    ZCert client_cert = new ZCert();
	    client_cert.setMeta("name", "Client test certificate");
	    ZCert server_cert = new ZCert();
	    //  Create and bind server socket
	    ZMQ.Socket server = ctx.createSocket(ZMQ.PUSH);
	    //  Create and connect client socket
	    ZMQ.Socket client = ctx.createSocket(ZMQ.PULL);
	    //  Send a single message from server to client
	    String message = client.recvStr(0,Charset.defaultCharset());
	    if (message.equals("Hello")) {
	    	System.out.println("Ironhouse test OK");

Tags : , ,
<< December 2016 | Home | February 2017 >>