All Downloads are FREE. Search and download functionalities are using the official Maven repository.

be.bagofwords.application.status.ListUrlsController Maven / Gradle / Ivy

Go to download

Utility classes that are used in the count-db project and other bow-* projects

The newest version!
package be.bagofwords.application.status;

import be.bagofwords.application.ApplicationContext;
import be.bagofwords.application.CloseableComponent;
import be.bagofwords.application.SocketServer;
import be.bagofwords.util.Pair;
import be.bagofwords.web.BaseController;
import spark.Request;
import spark.Response;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Koen Deschacht ([email protected]) on 07/10/14.
 */

public class ListUrlsController extends BaseController {

    private final List> urls;

    public ListUrlsController(ApplicationContext applicationContext) {
        super("/paths");
        this.urls = new ArrayList<>();
        new RegisterUrlsServer(this, applicationContext);
    }

    @Override
    protected String handleRequest(Request request, Response response) throws Exception {
        StringBuilder result = new StringBuilder();
        synchronized (urls) {
            for (Pair url : urls) {
                result.append("" + url.getFirst() + " " + url.getSecond() + "
"); } } return result.toString(); } public void registerUrl(String name, String url) { synchronized (urls) { Pair toRegister = new Pair<>(name, url); if (!urls.contains(toRegister)) { urls.add(0, toRegister); } while (urls.size() > 20) { urls.remove(urls.get(urls.size() - 1)); } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy