com.cimpress.puzzle.Main.java Source code

Java tutorial

Introduction

Here is the source code for com.cimpress.puzzle.Main.java

Source

/*
 * Copyright 2002-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cimpress.puzzle;

import java.util.List;

import org.apache.log4j.Logger;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Starts the Spring Context and will initialize the Spring Integration routes.
 *
 * @author JToadler
 * @since 1.0
 *
 */
public final class Main {

    public static Logger logger = Logger.getLogger(Main.class);

    public static void main(final String... args) {

        logger.debug("tt");

        ApplicationContext cntx = new ClassPathXmlApplicationContext("classpath:spring-integration-context.xml");

        AsyncLogger asyncLogger = cntx.getBean("asyncLogger", AsyncLogger.class);

        asyncLogger.log("Container loaded", String.class, Main.class, logger);
        PuzzleAPI puzzleAPI = cntx.getBean("puzzleAPI", PuzzleAPI.class);

        DateTime dt = new DateTime();
        Puzzle puzzle = puzzleAPI.generatePuzzle();

        // new SquareFinder().solvePuzzle(Environment.getPuzzleObject());
        List<Square> squareList = new SquareFinder().solvePuzzle(puzzle);
        System.out.println("Total squares :" + squareList.size());
        puzzleAPI.postSolution(squareList, puzzle.getId());
        DateTime d2 = new DateTime();
        Duration elapsedTime = new Duration(dt, d2);
        System.out.println("\nTotal Time Taken :" + elapsedTime.getStandardSeconds());
    }
}