Results 1 to 5 of 5
  1. #1
    snehal is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default Study Villonanny source code

    I am new to java and for a month I read a few books on Java. Those books are not so advanced but sufficient for starting in java.

    I wanted to study a software and help its community. Its a bit too advanced for me but if someone can read the source code maybe they can help me extract the basic of the codes. I mean by this show me it's core function relies in which module.

    I basically want to know how this code interact with http without using webrequest. Maybe it does and hidden somewhere. I wanted to learn how it logs to website it download the html page and extract data from it and how it post the data also. Once I know which function does this i will search the web and read about it.

    I've been able to do it in VB but now i want to learn in java as I hear java it's more robust for web application.


    regards
    Snehal

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    If it's open source code, then why don't you just ask? If it's not, why should we help you plagarise someone else's code, thereby making ourselves an accesory?

  3. #3
    snehal is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default best learning website

    its open source code. Unfortunately every body there are expert and are very less active. I can expect an answer in weeks and in my opinion only an expert can explain the codes as many newbie find it difficult to keep pace with them and eventually drop out.

    I am learning using Jcreator and netbean. My aim is to provide the community with a GUI as presently they dont have a gui.

    "why should we help you plagarise someone else's code, thereby making ourselves an accesory?" I dont know why you wrote this.

    Please make this thread sticky one and I would ask the admin of villonnany to link this to his forum as a guide for starter.
    Last edited by snehal; 06-09-2010 at 08:20 AM.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Quote Originally Posted by snehal View Post
    "why should we help you plagarise someone else's code, thereby making ourselves an accesory?" I dont know why you wrote this.
    Because, of course, if it were not open source, then that's exactly what you'd be doing.

    Also, most people here also have better things to do with their time than dig through someone elses code searching for things that may not even be there.

    Search the code yourself (the names of the classes and methods should give rather large hints as to what they're for) and post specific parts of the code that you would like more info about.

    Quote Originally Posted by snehal View Post
    Please make this thread sticky one and I would ask the admin of villonnany to link this to his forum as a guide for starter.
    I have no idea why anyone would think that a good idea, BTW.

  5. #5
    snehal is offline Member
    Join Date
    Jun 2010
    Posts
    8
    Rep Power
    0

    Default

    There are many classes and I believe villonanny.java is the main class.

    here it goes
    package net.villonanny;

    import java.io.OutputStreamWriter;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Locale;
    import java.util.Map;

    import net.villonanny.entity.Server;

    import org.apache.commons.configuration.AbstractFileConfi guration;
    import org.apache.commons.configuration.SubnodeConfigurat ion;
    import org.apache.commons.configuration.event.Configurati onEvent;
    import org.apache.commons.configuration.event.Configurati onListener;
    import org.apache.log4j.Logger;
    /**
    * Starts the Nanny, loads the configuration, starts each server, starts the console,
    */

    public class VilloNanny {
    private static final Logger log = Logger.getLogger(VilloNanny.class);
    public static SimpleDateFormat formatter = new SimpleDateFormat();
    private Map<String, Server> allServers; // ServerID -> Server instance
    private Date startTime = null;
    private static VilloNanny singleton;
    private ConfigManager configManager;
    private Console console;
    private boolean configurationJustReloaded = false; // True when the configuration has been reloaded and the VilloNanny hasn't been updated yet

    private VilloNanny(String[] args) throws DuplicateUidException {
    String configFilename = ConfigManager.DEFAULT_CONFIGFILE;
    configManager = new ConfigManager(configFilename);
    configManager.loadConfiguration();
    boolean modified = configManager.ensureUniqueIds();
    if (modified) {
    // uid's have been added: save configuration with backup
    configManager.saveXmlConfiguration();
    }
    formatter = new SimpleDateFormat(configManager.getString("/dateFormat", "EEE dd MMMM yyyy HH:mm:ss Z"));
    String waitUntil = Util.startTimeString(args);
    if (waitUntil!=null) {
    try {
    startTime = formatter.parse(waitUntil);
    // EventLog.log("Waiting until " + startTime);
    } catch (ParseException e) {
    String message = "Invalid date: " + waitUntil + "; format should be like \"" + formatter.format(new Date()) + "\"";
    EventLog.log(message);
    log.error(message, e);
    }
    }
    console = new Console(configManager);
    }

    public static void main(String[] args) {
    String s = VilloNanny.class.getSimpleName() + " " + Version.VERSION + " starting...";
    EventLog.log(s);
    EventLog.log("");
    EventLog.log("evt.start01", VilloNanny.class);
    EventLog.log("evt.start02", VilloNanny.class);
    EventLog.log("evt.start03", VilloNanny.class);
    EventLog.log("evt.start04", VilloNanny.class);
    EventLog.log("");
    Util.setUtf8(args);
    log.debug(String.format("Current os.name = %s, os.arch = %s, os.version = %s",
    System.getProperty("os.name"), System.getProperty("os.arch"), System.getProperty("os.version")));
    log.debug(String.format("Java version %s from %s", System.getProperty("java.version"), System.getProperty("java.vendor")));
    log.debug("Current locale = " + Locale.getDefault());
    log.debug("Current character encoding = " + new OutputStreamWriter(System.out).getEncoding());
    //
    if ("true".equalsIgnoreCase(System.getProperty("QUICK "))) {
    log.warn("!!! Forcing quick pause !!!");
    }
    // Check if we need to create an initial configuration, otherwise load it and run
    String configFilename = ConfigManager.DEFAULT_CONFIGFILE;
    ConfigManager configManager = new ConfigManager(configFilename);
    if (!configManager.isConfigurationThere()) {
    // The configuration file is not there, so call the autoconfigurator
    EventLog.log("evt.newConfigurationStart", VilloNanny.class);
    boolean success = new AutoConfigurator(configManager).configure();
    if (success) {
    EventLog.log("evt.newConfigurationEnd01", VilloNanny.class);
    EventLog.log("evt.newConfigurationEnd01b", VilloNanny.class, configManager.getString("/server/@version"));
    EventLog.log("evt.newConfigurationEnd02", VilloNanny.class, ConfigManager.CONFIGDIR);
    }
    } else {
    try {
    singleton = new VilloNanny(args);
    singleton.execute();
    } catch (DuplicateUidException e) {
    // Don't log, just exit
    }
    }
    EventLog.log("evt.exit", VilloNanny.class);
    }

    public static VilloNanny getInstance() {
    return singleton;
    }

    public Map<String, Server> getAllServers() {
    return allServers;
    }

    private void execute() {
    int totServers = 0;
    try {
    // First we create all servers and login, so that errors and user prompts won't occur at the delayed start
    // Create all servers
    allServers = createServerList();
    if (allServers.size()==0) {
    EventLog.log("No servers defined. Exiting...");
    return;
    }
    // Login to all servers, just to check credentials and prompt for missing passwords
    for (Server server : allServers.values()) {
    try {
    if (server.isEnabled()) {
    server.login();
    totServers++;
    }
    } catch (ConversationException e) {
    EventLog.log("Can't login, disabling server \"" + server.getServerDesc() + "\"");
    server.setEnabledAndStartStop(false);
    }
    }
    if (totServers==0) {
    EventLog.log("msg.noServers", this.getClass());
    return;
    }
    //
    // Delayed start
    if (startTime!=null) {
    Util.sleep(startTime.getTime() - System.currentTimeMillis());
    }
    //
    // Start Console
    console.start();
    // Start all servers
    for (Server server : allServers.values()) {
    server.begin();
    }
    configManager.addListener(getConfigurationListener ());
    //
    while (!console.isQuitting()) {
    try {
    Thread.sleep(4000);
    } catch (InterruptedException e) {
    // Ignored
    }
    if (isConfigurationJustReloaded()) {
    try {
    // Update server list
    Map<String, Server> addedServers = updateServerList(allServers);
    // Start all new servers
    for (Server server : addedServers.values()) {
    server.begin();
    }
    } catch (Exception e2) {
    log.error("Failed to update configuration", e2);
    }
    setConfigurationJustReloaded(false);
    }
    }
    try {
    console.join(); // This thread will wait here until the console is terminated
    } catch (InterruptedException e) {
    log.debug("Interrupted");
    }
    // Wait for all servers to terminate
    for (Server server : allServers.values()) {
    try {
    server.join();
    } catch (InterruptedException e) {
    log.debug("Interrupted");
    }
    }
    } catch (Exception e) {
    Util.log("Program error", e);
    EventLog.log(e.getMessage());
    EventLog.log("Aborting...");
    }
    // EventLog.log("...done.");
    }

    private ConfigurationListener getConfigurationListener() {
    return new ConfigurationListener() {
    Thread nannyThread = Thread.currentThread();
    public void configurationChanged(ConfigurationEvent event) {
    if (event.getType() == AbstractFileConfiguration.EVENT_RELOAD && !event.isBeforeUpdate()) {
    setConfigurationJustReloaded(true);
    nannyThread.interrupt(); // Awake from sleep
    }
    }
    };
    }

    /**
    * Initial creation of the server list
    * @return
    */
    private Map<String, Server> createServerList() {
    return updateServerList(new HashMap<String, Server>());
    }

    /**
    * If servers are added or deleted, modify the server list
    * @param theServers the previous servers
    * @return the map of added servers than need to be started
    */
    private Map<String, Server> updateServerList(Map<String, Server> theServers) {
    log.debug("Updating server list");
    List<Server> deletableServers = new ArrayList<Server>(theServers.values());
    Map<String, Server> addedServers = new HashMap<String, Server>();

    try {
    List<SubnodeConfiguration> serverConfigs = configManager.configurationsAt("/server");
    for (SubnodeConfiguration serverConfig : serverConfigs) {
    // Configuration is cloned so that it is not wiped on reload
    SubnodeConfiguration serverConfigurationCopy = (SubnodeConfiguration) serverConfig.clone();
    String serverId = Server.idFromConfig(serverConfig);
    Server existingServer = theServers.get(serverId);
    if (existingServer==null) {
    // New server added
    Server newServer = new Server(serverConfigurationCopy, configManager, console);
    addedServers.put(serverId, newServer);
    theServers.put(serverId, newServer);
    } else {
    // Existing server
    if (addedServers.values().contains(existingServer)) {
    // Server just added
    EventLog.log("evt.duplicateServer", this.getClass(), serverId);
    continue;
    }
    deletableServers.remove(existingServer); // Remove this server from the deletable servers
    // When the configuration is reloaded, the SubnodeConfiguration that was previously contained in the Server
    // is not automatically updated:
    // SubnodeConfiguration (Commons Configuration 1.6 API)
    // Server configuration is updated only when the server chooses to do so (not while in the middle of a strategy)
    // existingServer.updateConfig(serverConfig);
    existingServer.setNextConfiguration(serverConfigur ationCopy);
    // Check if enabled/disabled has changed on an existing server
    boolean enabledInConfig = serverConfig.getBoolean("/@enabled", true);
    existingServer.setEnabledAndStartStop(enabledInCon fig);
    }
    }
    // Now removedServers contains all servers that are not in the configuration anymore
    // and addedServers contains all new servers
    // Stop and delete all removed servers
    for (Server removedServer : deletableServers) {
    removedServer.terminate();
    theServers.remove(removedServer.getServerId());
    }
    } catch (InvalidConfigurationException e) {
    log.error("Configuration error", e);
    EventLog.log("msg.reloadAborted", VilloNanny.class);
    }
    return addedServers;
    }

    private synchronized boolean isConfigurationJustReloaded() {
    return configurationJustReloaded;
    }

    private synchronized void setConfigurationJustReloaded(boolean configurationJustReloaded) {
    this.configurationJustReloaded = configurationJustReloaded;
    }



    }

    I am not sure where it catches the url. Its not straight forward. If someone can help me to figure it out. The configuration is stored in an xml file.

    I think it call configmanager.java and there its process the xml file but still what instruction is issued to capture the html file data.Maybe this will be in another class. If you were to do a project like villonnany is there alternatives way or only one for capturing html file and interpreting the data.

Similar Threads

  1. How can i add a new count to this source code ?
    By mm2236 in forum New To Java
    Replies: 2
    Last Post: 01-31-2010, 03:32 AM
  2. Replies: 1
    Last Post: 11-28-2008, 06:27 PM
  3. Replies: 2
    Last Post: 10-23-2008, 05:43 PM
  4. Help me out in compiling the source code
    By aks.nitw in forum Advanced Java
    Replies: 3
    Last Post: 10-17-2008, 08:33 AM
  5. Need a source code
    By vissu007 in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •