[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
cluster a tcp server  XML
Forum Index -> Terracotta Platform
Author Message
zeeiyer

consul

Joined: 05/24/2006 14:28:28
Messages: 493
Offline

Posting for AkshanthaKumar:
=====================
Hi

How do I cluster a TCP server. I am not sure how to go about it. Lets say I have a code below, how would I enable clustering on it using Terracotta and what benefits would I get by clustering using Terracotta like would the threads be moved to workers.

Code:
 import java.net.*;
 import java.io.*;
 
 class TestServer extends Thread {
     public TestServer() {
         super("Demo");
         start();
     }
 
     public void run() {
         ServerSocket acceptSocket=null;
         try {
             acceptSocket = new ServerSocket(123);
             while(true) {
                 final Socket s = acceptSocket.accept();
                 Thread t = new Thread() {
                     public void run() {
                         try {
                             doRequest(s);
                         } catch(Exception err) {
                             System.out.println("Error at client :"+err);
                         }
                     }
                 };
                 t.start();
             }
         } catch (IOException e) {
             System.out.println("Error at server :"+e);
         } finally {
             try {
                 acceptSocket.close();
             }catch(Exception re){
                 throw new RuntimeException(re);
             }
         }
     }
 
     public final void doRequest(Socket s) throws IOException {
         InputStream in = s.getInputStream();
         OutputStream out=s.getOutputStream();
         PrintWriter rout=new PrintWriter(
         new BufferedOutputStream(out));
         rout.println("Hello");
         rout.flush();
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e){
             System.out.println("Do request thread interrupted : "+e);
         } finally {
             out.close();
         }
         s.close();
     }
 
     public static void main(String args[]) {
         new TestServer();
     }
 }

=====================
Regards, Akshathkumar Shetty
Tech Lead
enStage Software Pvt. Ltd.
Email: ashetty@enstage.com Off: +91-80-25204351, 80-32722080 Telefax: +91-8025204350 Bangalore, India

Sreeni Iyer, Terracotta.
Not a member yet - Click here to join the Terracotta Community
kbhasin

consul

Joined: 12/04/2006 13:08:21
Messages: 340
Offline

Hello AkshanthaKumar,

I am not quite sure why you would want to cluster a Thread. If the Threads on your TCP Server hold some state, Terracotta could be used to cluster that state data. e.g., in yur example, if you had some fields in the TestServer class, you could share them with Terracotta.

Here are some good links to get started:

http://www.terracotta.org/confluence/display/orgsite/TutorialTerracottaDsoSlider

http://www.terracotta.org/confluence/display/docs22/Terracotta+DSO+Install+and+Setup+Guide

Regards,
Kunal.

Regards,

Kunal Bhasin,
Terracotta, Inc.

Be a part of the Terracotta community: Join now!
 
Forum Index -> Terracotta Platform
Go to:   
Powered by JForum 2.1.7 © JForum Team