• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Client-server transforming

I have desktop app which is run at my iMac.
I would like to transfer it to the server and left on iMac only chart.
public class Main {

    private static Timer timer;
    private static ChartControl chartControl;

    public static void main(String[] args) throws Exception {

        chartControl = new ChartControl();
        callSelect();
        //    chartControl = new ChartControl();
    }


    /**
     * @throws Exception
     */
    public static void callSelect() throws Exception {
        try {
            timer = new Timer();
            timer.schedule(new SelectData(), 10000, 1000);

            System.out.println("          switch on the Timer");
            System.out.println("=>");

        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

Open in new window

public class SelectData extends TimerTask {

    private ConnectDB conn;

    double bb;
    double bs;
    double bpx;
    double apx;

    String bot_buy0 = null;
    String bot_sell0 = null;

    public SelectData() throws SQLException, ClassNotFoundException,
                               IllegalAccessException, InstantiationException,
                               Exception {
        conn = new ConnectDB();
    }

    public void run() {
        try {
            List<DataStream> dataList =
                conn.selectStream("SELECT * FROM EURUSD where timest = ( select max( timest ) from EURUSD ) and rownum = 1 "); 


            for (DataStream data : dataList) {

                String s;

                s = data.getSymbol();
                bpx = data.getOpenBid();
                apx = data.getOpenAsk();

                if (s.equals("EUR/USD")) {

                    TimeSeriesEURUSD.getInstance().doEvent(apx, bpx, bb, bs);

                } 
            }
        } catch (Exception ex) {
            Logger.getLogger(SelectData.class.getName()).log(Level.SEVERE,
                                                             null, ex);
        }

        try {


            List<DataBuy> dataList =
                conn.selectBuy("SELECT * FROM EURUSD_BOT_BUY where ts = ( select max( ts ) from EURUSD_BOT_BUY ) and rownum = 1 "); 
            for (DataBuy data : dataList) {

                String s;
                Timestamp tsb;
                String bot_buy;
               
                s = data.getSymbol();
                tsb = data.getTs();  
                bot_buy = data.getBuyPx();

                    if (bot_buy.equals(bot_buy0))
                        
                    continue;

                bot_buy0 = bot_buy; 
                             
                bb = Double.parseDouble(bot_buy);

                if (s.equals("EUR/USD"))
                {
                    TimeSeriesEURUSD.getInstance().doEvent(apx, bpx, bb, bs);
                } 
            }
        } catch (Exception ex) {
            Logger.getLogger(SelectData.class.getName()).log(Level.SEVERE,
                                                             null, ex);
        }


        try {

            List<DataSell> dataList =
                conn.selectSell("SELECT * FROM EURUSD_BOT_SELL where ts = ( select max( ts ) from EURUSD_BOT_SELL ) and rownum = 1 ");
 
            for (DataSell data : dataList) {

                String s;
                Timestamp tss;
                String bot_sell;

                s = data.getSymbol();
                tss = data.getTs();
                bot_sell = data.getSellPx();

                if (bot_sell.equals(bot_sell0))
                    continue;

                bot_sell0 = bot_sell;
                
                bs = Double.parseDouble(bot_sell);

                if (s.equals("EUR/USD")) {

                    TimeSeriesEURUSD.getInstance().doEvent(apx, bpx, bb, bs);

                } 
            }

        } catch (Exception ex) {
            Logger.getLogger(SelectData.class.getName()).log(Level.SEVERE,
                                                             null, ex);
        }
    }
  }

Open in new window

public class TimeSeriesEURUSD extends JFrame {

    public static final TimeSeriesEURUSD INSTANCE = new TimeSeriesEURUSD();

    /**
     * @return
     */
    public static TimeSeriesEURUSD getInstance() {
        return INSTANCE;
    }


    public TimeSeriesEURUSD() {

        setContentPane(chartPanel);
        setSize(1800, 800);
        setVisible(true);
    }

    TimeSeries s1 = new TimeSeries("s1");
    TimeSeries s2 = new TimeSeries("s2");
    TimeSeries s3 = new TimeSeries("s3");
    TimeSeries s4 = new TimeSeries("s4");

    int sc1 = 0;
    int sc2 = 0;
    int sc3 = 0;
    int sc4 = 0;
    
    double[] cbb = new double[3];
    double[] cbs = new double[3];
    int j;

    public void doEvent(double apx, double bpx, double bb, double bs) {

        sc1++;
        sc2++;
        sc3++;
        sc4++;

        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bpx));

        if (sc1 > 1800) {
            s1.delete(0, 0);
        }
        
        s4.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(apx));

        if (sc4 > 1800) {
            s4.delete(0, 0);
        }
        
          for (int j = 2; j > 0; j--) {

              cbb[j] = cbb[j - 1];
              cbs[j] = cbs[j - 1];
          } 
          
              cbb[j] = bb;
              cbs[j] = bs;

        if (bb != 0 && cbb[0] != cbb[1]) {

            s2.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                           new Float(bb));

            System.out.println("    doEvent  >>>>>>>      bb = " + bb);
            System.out.println();

            if (sc2 > 20) {
                s2.delete(0, 0);
            }
        }

        if (bs != 0 && cbs[0] != cbs[1]) {

            s3.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                           new Float(bs));

            System.out.println("    doEvent  >>>>>>>     bs = " + bs);
            System.out.println();

            if (sc3 > 20) {
                s3.delete(0, 0);
            }
        } 
    }


    private JFreeChart createChart(XYDataset dataset) {

        JFreeChart chart =
            ChartFactory.createTimeSeriesChart("EUR/USD", // title
                "Time", // x-axis label
                "EUR/USD Bot Signals", // y-axis label
                dataset, // data
                true, // create legend?
                true, // generate tooltips?
                false); // generate URLs?
        

        chart.setBackgroundPaint(Color.white);

        chart.addSubtitle(new TextTitle("Bot Statistics for EUR/USD"));

        XYPlot plot = (XYPlot)chart.getPlot();

        plot.setBackgroundPaint(Color.lightGray);

        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);

        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

        plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);

        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, true);
        renderer.setSeriesShapesVisible(0, false);

            renderer.setSeriesLinesVisible(1, false);
            renderer.setSeriesShapesVisible(1, true);

        renderer.setSeriesLinesVisible(2, false);
        renderer.setSeriesShapesVisible(2, true);

        renderer.setSeriesLinesVisible(3, true);
        renderer.setSeriesShapesVisible(3, false);

        plot.setRenderer(renderer);


        renderer.setSeriesPaint(0, Color.blue);
        renderer.setSeriesPaint(1, Color.green);
        renderer.setSeriesPaint(2, Color.red);
        renderer.setSeriesPaint(3, Color.yellow);


        DateAxis axis = (DateAxis)plot.getDomainAxis();
        axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss"));

        return chart;
    }

    public XYDataset createDataset() {

        TimeSeriesCollection dataset = new TimeSeriesCollection();

        dataset.addSeries(s1);
        dataset.addSeries(s2);
        dataset.addSeries(s3);
        dataset.addSeries(s4);

        return dataset;
    }

    public JPanel createDemoPanel() {

        JFreeChart chart = createChart(createDataset());
        ChartPanel panel = new ChartPanel(chart);
        panel.setFillZoomRectangle(true);
        panel.setMouseWheelEnabled(true);

        return panel;
    }
   ChartPanel chartPanel = (ChartPanel)createDemoPanel();
}

Open in new window

Please advice how to split it.
0
gbcbr
Asked:
gbcbr
  • 10
  • 10
1 Solution
 
for_yanCommented:
You data seesm to be coming from some database - all these select statements - ?
0
 
gbcbrAuthor Commented:
yes, this DB located on this server also.
My general idea is to move all calculations to the server, because it's very strong and left on iMac only control and charts.
OK, my Mac also strong 2,93GHz Core i7, 16Gb 1333MHz DDR3, but I would like to move everything to server.
0
 
for_yanCommented:
I frankly don't see any calculations there - you are just grabbing data from database.
You can have three-tier architecture with app server, but I don't see much difference.

Do you want to make a web page of your chart?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gbcbrAuthor Commented:
Calculations, I mean all back-office jobs: getting data, sorting and displaying.
I suppose that web page will be good solution for this case.
0
 
for_yanCommented:
That is a rather big deal.
Do you have a web server and/or Java engine, like Tomcat.
did you vere do any servlets or something like that?
0
 
gbcbrAuthor Commented:
My server OS Solaris 10. I have GlassFish installed, but I never use it. I can install Apache, or WebLogic Server, whatever you advise.
I have NetBeans 7 installed on this server. Let's start and we'll continue, question by question, I prefer solve questions, step by step.
0
 
for_yanCommented:

Well, it depends on the preference.
Weblogic is probably the best, but I prefer Apache/Tomcat combination;
you can use only Tomcat, as the Apache-Tomcat linkage on Solaris is
much less straighforward (well, installation also) than it is on windows.

In general, it seems to be too big subject
You'll have to learn a lot about servlets and all that stuff.
Don't know - maybe there is a simpler way.
0
 
gbcbrAuthor Commented:
OK, give me some time to study this question and I'll come back soon with new knowledge )))
0
 
for_yanCommented:
OK.
0
 
gbcbrAuthor Commented:
I've installed last JDeveloper Studio with integrated WebLogic server on my iMac. On this iMac I have this BotCharts application. Everything work fine. Now the question how to transform this application into client-server application and call different charts as a web pages.
0
 
for_yanCommented:
Still cannot say I understand what it is that you  want to do
0
 
gbcbrAuthor Commented:
I have GUI which invoke all charts, but they work all together in one desktop app, so I need to split them and move logical part to server and have only GUI on the remote Mac.
I don't like to put all this study processes on my main Solaris server now. Only after understanding procedure.
0
 
gbcbrAuthor Commented:
I read about creating new EE and ADF application. For me now is the main question it splitting of all my working desktop applications without destroying, just move them to server and control them from iPad via web interface.
0
 
for_yanCommented:
I don't think your Java GUI will be of much value to you if you now want to create Web - -possibly Java Faces I guess application.

It would be only useful as a design model - so you'll have idea what interface user may want if
 your GUI is suitable - the actual implementation will be of course  quite differently.
So your web logic would server as middle tier - you'll get data form some database and
browser will be the front end.

Whatever you have now as a standalone java application will be only of use in ideological sense, technically
almost everything will be different.
0
 
gbcbrAuthor Commented:
So, I have to create almost new application and use old application only as a base for logic?
0
 
for_yanCommented:
That is how I see it - along the way you'll learn weblogic, JSF, and many other useful things
0
 
gbcbrAuthor Commented:
OK, I will :-(
0
 
for_yanCommented:
Wish you good luck.
You'll have very useful skills.
0
 
gbcbrAuthor Commented:
Thank you
0
 
for_yanCommented:
You are always welcome.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 10
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now