> Please try to respect the concerns of others.

In my previous postings I tried to convince others that there was no reason
for concerns. I tried to minimize the code changes to remove all concerns
and tried to explain what I have done to the old code.

> From your postings I understand that all you really need in 
> the Vodafone environment is a unicast alternative for the 
> present multicasting. I'm confident that a hack-proposal to 
> add support for this in CVS HEAD would have passed the vote. 
> That would be all you need, because in that case you could 
> apply the patch locally, and be confident that the it would 
> remain to be supported in future releases of MMBase. For some 
> reason you chose to modify the existing multicasting 
> behaviour as well, which caused the proposal to be rejected. 
>
> I respect you opinion, but I don't approve if you bail out 
> that easily.
> I think that ommitters have a moral obligation to show a fair 
> amount of good will to come to a mutually acceptable 
> solution. One way for you to do so is to rephrase your 
> proposal - leaving out the multicast modification - and resubmit it. 
> Please do.

Actually, I didn't need a change in the MMBase code for the Vodafone
environment. Just overriding some methods of the old MMBasMultiCast would
have been sufficient. I wouldn't have offered the hack if it stayed that
way. Below is the code how my first version looked like and what my proposal
would be without the multicast modification. UniCastChangesSender would be
the same as it is now.

public class MMBaseUniCast extends MMBaseMultiCast {
    private static Logger log =
Logging.getLoggerInstance(MMBaseUniCast.class.getName());
    public static final String CONFIG_FILE = "unicast.xml";
    private int unicastPort = 4243;
    private int unicastTimeout = 10*1000;
    private UniCastChangesSender ucs;
    private MultiCastChangesReceiver ucr;
    
    public MMBaseUniCast(MMBase parent) { super(parent); }
    
    public void init() {
        UtilReader reader = new UtilReader(CONFIG_FILE);
        Map properties = reader.getProperties();
        String tmp = (String) properties.get("unicastport");
        if (tmp != null && !tmp.equals("")) {
            try { unicastPort = Integer.parseInt(tmp); } catch (Exception e)
{}
        }
        tmp = (String) properties.get("unicasttimeout");
        if (tmp != null && !tmp.equals("")) {
            try { unicastTimeout = Integer.parseInt(tmp); } catch (Exception
e) {}
        }
        start();
    }
    
    protected void start() {
        if (kicker == null) {
            kicker = new Thread(this,"MMBaseUniCast");
            kicker.setDaemon(true);
            kicker.start();
            ucs = new UniCastChangesSender(unicastPort, unicastTimeout,
nodesToSend, mmbase);
            ucr=new MultiCastChangesReceiver(this,nodesTospawn);
        }
    }

    public boolean changedNode(int nodenr, String tableName, String type) {
        nodesToSpawn.append(message);
        return super.changedNode(nodenr, tableName, type);
    }
    
    public void doWork() {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(unicastPort);
            while (kicker!=null) {
                Socket socket = null;
                InputStream reader = null;
                try {
                    socket = serverSocket.accept();
                    reader = new
BufferedInputStream(socket.getInputStream());
                    ByteArrayOutputStream writer = new
ByteArrayOutputStream();
                    int size = 0;
                    byte[] buffer = new byte[1024];
                    while ((size = reader.read(buffer)) != -1) {
                        if (writer != null) {
                          writer.write(buffer, 0, size);
                          writer.flush();
                       }
                    }
                    nodesToSpawn.append(new String(writer.toByteArray()));
                } catch (Exception e) {
                    log.error(Logging.stackTrace(e));
                }
                finally {
                    if (reader != null) {
                        try { reader.close(); } catch (IOException e) {}
                    }
                    if (socket != null) {
                        try { socket.close(); } catch (IOException e) {}
                    }
                }
                incount++;
            }
        } catch (Exception e) { log.error(Logging.stackTrace(e)); }
        finally {
            if (serverSocket != null) {
                try { serverSocket.close(); } catch (IOException e) {}
            }
        }
    }
}

My line of thinking when I saw this piece of working code:
What if I switch the MultiCastChangesReceiver.doWork() and the doWork()
method with socket handling? Hmm that is neat only a few lines which mention
MultiCast.
What if I move all non-related multicast stuff to a base class and extend
this for multicast and unicast.
He, this looks like a nice hack proposal. What more can I add to it what was
requested on the list? 
Where are so many threads spawned? He, these two lines could be replaced by
just a method.
Done.

Again, I didn't need a change, but I was allowed to spend some extra time on
it to have a cleaner implementation. The submitted code adds readablity and
shows an alternative implementation.

Nico


Reply via email to