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; } } 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(); } } } <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>


上一篇:
下一篇:
切换中文