```java import org.jgroups.JChannel; import org.jgroups.Message; import org.jgroups.ReceiverAdapter; import org.jgroups.View; public class GroupCommunicationExample extends ReceiverAdapter { private JChannel channel; public GroupCommunicationExample(String clusterName) throws Exception { channel = new JChannel(); channel.setReceiver(this); channel.connect(clusterName); } public void sendMessage(String message) throws Exception { Message msg = new Message(null, null, message); channel.send(msg); } @Override public void receive(Message message) { System.out.println("Received message: " + message.getObject()); } @Override public void viewAccepted(View newView) { System.out.println("New cluster view: " + newView); } public static void main(String[] args) { try { GroupCommunicationExample example = new GroupCommunicationExample("MyCluster"); example.sendMessage("Hello world"); } catch (Exception e) { e.printStackTrace(); } } } ``` ```xml <config xmlns="urn:org:jgroups" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"> <TCP bind_addr="127.0.0.1" bind_port="7800" enable_diagnostics="false" thread_pool.min_threads="2" thread_pool.max_threads="4"/> <TCPPING timeout="3000" initial_hosts="${jgroups.tcpping.initial_hosts:localhost[7800],localhost[7801]}" port_range="10"/> <MERGE2 min_interval="10000" max_interval="30000"/> <FD_SOCK/> <FD_ALL timeout="3000" interval="1000" timeout_check_interval="2000"/> </config> ```

```java import org.jgroups.JChannel; import org.jgroups.Message; import org.jgroups.ReceiverAdapter; public class DistributedCalculator extends ReceiverAdapter { private JChannel channel; public DistributedCalculator() throws Exception { channel = new JChannel(); channel.setReceiver(this); channel.connect("distributed-calculation"); } public void executeTask(Task task) { try { Message message = new Message(null, task); channel.send(message); } catch (Exception e) { e.printStackTrace(); } } @Override public void receive(Message message) { Task task = (Task) message.getObject(); Result result = execute(task); try { Message response = new Message(message.getSrc(), result); channel.send(response); } catch (Exception e) { e.printStackTrace(); } } @Override public void viewAccepted(View view) { } private Result execute(Task task) { return null; } } ``` ```java import org.jgroups.JChannel; import org.jgroups.blocks.locking.LockService; import java.util.concurrent.locks.Lock; public class DistributedLock { public static void main(String[] args) throws Exception { JChannel channel = new JChannel(); LockService lockService = new LockService(channel); Lock lock = lockService.getLock("shared-lock"); lock.lock(); try { } finally { lock.unlock(); } } } ``` ```xml <config xmlns="urn:org:jgroups" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups-3.6.xsd"> <TCP bind_port="7800" recv_buf_size="5M" send_buf_size="5M" max_bundle_size="64K" max_bundle_timeout="30" use_send_queues="true" sock_conn_timeout="300" thread_pool.min_threads="0" thread_pool.max_threads="100" thread_pool.keep_alive_time="30000"/> <PING timeout="2000" num_initial_members="3"/> <MERGE2 max_interval="30000" min_interval="10000"/> <FD_SOCK/> <FD_ALL timeout="3000" interval="1500" timeout_check_interval="3000"/> <VERIFY_SUSPECT timeout="1500"/> <pbcast.NAKACK2 use_mcast_xmit="false" discard_delivered_msgs="true"/> <UNICAST3 xmit_table_num_rows="100" xmit_table_msgs_per_row="5000" xmit_interval="500" conn_expiry_timeout="0"/> <pbcast.STABLE desired_avg_gossip="50000" max_bytes="4M"/> <pbcast.GMS print_local_addr="true" join_timeout="3000"/> <MFC max_credits="2m" min_threshold="0.4"/> <FRAG2 frag_size="60K"/> <pbcast.STATE_TRANSFER/> <pbcast.FLUSH/> </config> ```

``` import org.eclipse.epsilon.emc.emf.EmfModel; import org.eclipse.epsilon.emc.emf.EmfUtil; import org.eclipse.epsilon.emc.emf.EpsilonResourceSet; EpsilonResourceSet resourceSet = new EpsilonResourceSet(); EmfUtil.register(URI.createURI("path/to/metamodel.ecore"), EPackage.Registry.INSTANCE); EmfModel model = new EmfModel(); model.setMetamodelFile("path/to/metamodel.ecore"); model.setModelFile("path/to/model.xmi"); model.setName("MyModel"); model.setReadOnLoad(true); model.setStoredOnDisposal(false); model.setCachingEnabled(true); model.setExpand(true); model.setReuseUnmodifiedMetamodels(true); model.load(); Object rootElement = model.getModelImpl().getResource().getContents().get(0); model.store(); ``` ``` import org.eclipse.epsilon.emc.emf.EmfModel; import org.eclipse.epsilon.eol.EolModule; EolModule module = new EolModule(); module.getContext().getModelRepository().addModel(model); module.execute(); List<Object> result = (List<Object>) module.getContext().getFrameStack().get(0).get(0); for (Object element : result) { } ``` ``` import org.eclipse.epsilon.eol.models.IModel; import org.eclipse.epsilon.eol.models.ModelFactory; IModel inputModel = ModelFactory.getInstance().createModel("EMF"); inputModel.load("path/to/inputModel.xmi"); IModel outputModel = ModelFactory.getInstance().createModel("EMF"); outputModel.create(); outputModel.setName("OutputModel"); EtlModule module = new EtlModule(); module.getContext().getModelRepository().addModel(inputModel); module.getContext().getModelRepository().addModel(outputModel); module.execute(); ``` ``` import org.eclipse.epsilon.eol.models.IModel; import org.eclipse.epsilon.eol.models.ModelFactory; IModel model = ModelFactory.getInstance().createModel("EMF"); model.load("path/to/model.xmi"); String template = "path/to/template.egl"; EglFileGeneratingTemplateFactory templateFactory = new EglFileGeneratingTemplateFactory(); EGxModule module = new EGxModule(templateFactory); module.parse(template); module.getContext().getModelRepository().addModel(model); module.execute(); ```