Monday, January 28, 2019

Metlink Wellington Bus Delays Realtime Charts

Metlink Bus Graphs

Thursday, September 14, 2017

New Zealand Election 2017 : Give me Why not What

Today I watched a 7 minute video about Bill English, purportedly emailed to me personally by his wife. I replied:

That's all well and good, but I still have no idea what drove Bill to enter politics. Why is he here? Jacinda Ardern said she entered politics to end homelessness, and it is clearly a fundamental cause she believes in. Why did Bill enter politics?

The political party web sites talk about what they plan to do but scarcely elaborate on why.  To vote for a party, I need to know at a fundamental level why that party exists, and why it's members have chosen to be associated with it.  Some MPs I have observed appear to be in politics chiefly to meet their needs for recognition and status, not because they have a fervent zeal for any particular cause.

Look at National's web site.  Under "Our Values" they list their top three as "Less debt, more jobs, strong stable government".  Those are not values!

Look a Labour's.  No mention of values, but a confronting question: "Are you with Jacinda and us?" I'll vote for a party with a purpose, not for a personality.

The Green Party's landing page lists three objectives "Clean Water, End Poverty, Climate Action".  There is no explanation as to why the Green Party considers these to be so important.

The Maori party web site does not explain why the Maori party exists.  Make your way through the requests for funding and you'll find the slogan "Strong Independent Voice".  But why is the Maori Party bothering at all?

Act's web site looks like propaganda for the cult of David Seymour.

New Zealand First's web site doesn't directly address my why questions, but it does have a major section called "Our Fifteen Principles" which goes some way to explaining the parties core purpose.

The web site of the Opportunities Party gives me what I'm looking for: "Help make New Zealand fair".  That's why they exist, they want to make New Zealand fair.  Even better, they have a major section called "Vision" which states "All people have aspirations, and all of us have a right to fulfil those aspirations. We also have a responsibility to ensure others have the same opportunity".  That's why they exist.

If I was driven to enter politics the fundamental reason why would be because I find inequality abhorrent.  A society in which some people have too much while others have too little is disgusting and dehumanising. Everything a person achieves in life comes down to luck, and basic humanity dictates that those who have been fortunate ought to share their gains with those who have been unlucky.  The family you were born into, your health, your genetic makeup, the values that you were taught, whether or not you were encouraged and supported to work hard and extend yourself, all of these are the product of luck.  And when the lucky turn their backs on the unlucky, how can I not be disgusted.

Monday, November 7, 2016

A Tool to Bulk Move ActiveMQ Messages

This java algorithm can be used to mass-move messages from one ActiveMQ queue to another.

package com.nixon;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
 
import org.apache.activemq.ActiveMQConnectionFactory;
 
/**
 * Depends on activemq-all-5.11.1.jar
 */
public class MqBulkMove {
 
    private int DEFAULT_THROTTLE_MS = 20;
 
    public static void main(String... args) {
 
        if (args == null || args.length != 4) {
            System.out.println("Usage: java -jar mqmove.jar broker-url source-queue dest-queue max-messages");
            System.out.println("Example: java -jar mqmove.jar tcp://activemq01.nixon.com:61616 REQUEST_DQ REQUEST 1");
            return;
        }
 
        String brokerUrl = args[0];
        String sourceQueue = args[1];
        String destQueue = args[2];
        int maxNumberOfMessagesToMove = Integer.valueOf(args[3]);
 
        try {
            boolean success = new MqBulkMove().bulkMove(brokerUrl, sourceQueue, destQueue, maxNumberOfMessagesToMove);
            System.exit(success ? 0 : -1);
        }
        catch (Exception ex) { throw new RuntimeException(ex); }
    }
 
    private boolean bulkMove(String activeMqBrokerUrl, String sourceQueue, String destQueue, int maxNumberOfMessagesToMove) throws Exception {
        AMQ amq = null;
        try {
            amq = new AMQ(activeMqBrokerUrl, sourceQueue, destQueue);
 
            amq.producer.setDeliveryMode(DeliveryMode.PERSISTENT);
 
            if (!confirm(maxNumberOfMessagesToMove, sourceQueue, destQueue)) {
                System.out.println("EXIT");
                return false;
            }
 
            int numberOfMessagesMoved = 1;
            while (numberOfMessagesMoved <= maxNumberOfMessagesToMove) {
                Message message = null;
                try {
                    message = amq.consumer.receive(1000);
 
                    System.out.println("Received message " + numberOfMessagesMoved);
                }
                catch (JMSException ex) {
                    ex.printStackTrace();
 
                    System.out.println("Failed to receive message " + numberOfMessagesMoved);
                    System.out.println("Exit:ERROR");
                    return false;
                }
 
                if (message == null) {
                    System.out.println("Message is null");
                    System.out.println("Exit::ERROR");
                    return false;
                }
 
                try {
                    amq.producer.send(message);
 
                    // Acknowledge the message only if copy was successful
                    message.acknowledge();
                }
                catch (JMSException ex) {
                    ex.printStackTrace();
                    if (message instanceof TextMessage) {
                        TextMessage textMessage = (TextMessage) message;
                        String text = textMessage.getText();
                        System.out.println("Failed to send message to " + destQueue + " : " + text);
                    } else {
                        System.out.println("Failed to send message to " + destQueue + " : " + message);
                    }
                    System.out.println("Exit::ERROR");
                    return false;
                }
                System.out.println("Sent message " + numberOfMessagesMoved);
 
                Thread.sleep(DEFAULT_THROTTLE_MS);
 
                numberOfMessagesMoved++;
            }
 
            System.out.println("Exit::SUCCESS");
        }
        catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("Exit:ERROR");
            return false;   
        }
        finally {
            if (amq!=null){amq.close();}
        }
       
        return true;
    }
 
    private boolean confirm(int maxNumberOfMessagesToMove, String sourceQueue, String destQueue) {
        System.out.println("-------------------------------------------------------------");
        System.out.println("Moving " + maxNumberOfMessagesToMove + " messages (at most) from " + sourceQueue + " to " + destQueue);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("confirm? [y/n]");
        boolean isConfirmed = false;
        try {
            String input = reader.readLine();
            isConfirmed = "y".equalsIgnoreCase(input);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (!isConfirmed) {
            return false;
        }
 
        System.out.println("-------------------------------------------------------------");
        return true;
    }
 
    private class AMQ {
       
        Connection connection;
        Session session;
 
        Destination source;
        Destination destination;
        MessageConsumer consumer;
        MessageProducer producer;
 
        public AMQ(String activeMqBrokerUrl, String sourceQueue, String destQueue) throws JMSException {
 
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(activeMqBrokerUrl);
 
            connection = connectionFactory.createConnection();
            connection.start();
 
            session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
 
            source = session.createQueue(sourceQueue);
            destination = session.createQueue(destQueue);
 
            consumer = session.createConsumer(source);
 
            producer = session.createProducer(destination);
        }
 
        public void close() throws JMSException {
            try{producer.close();}catch(Exception ex){ex.printStackTrace();}
            try{consumer.close();}catch(Exception ex){ex.printStackTrace();}
            try{session.close();}catch(Exception ex){ex.printStackTrace();}
            try{connection.close();}catch(Exception ex){ex.printStackTrace();}
        }
    }
 
}