Initial commit
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package dslab;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import dslab.mailbox.IMailboxServer;
|
||||
import dslab.mailbox.MailboxServer;
|
||||
import dslab.monitoring.IMonitoringServer;
|
||||
import dslab.monitoring.MonitoringServer;
|
||||
import dslab.transfer.ITransferServer;
|
||||
import dslab.transfer.TransferServer;
|
||||
import dslab.util.Config;
|
||||
|
||||
/**
|
||||
* The component factory provides methods to create the core components of the application. You can edit the method body
|
||||
* if the component instantiation requires additional logic.
|
||||
*
|
||||
* Do not change the existing method signatures!
|
||||
*/
|
||||
public final class ComponentFactory {
|
||||
|
||||
private ComponentFactory() {
|
||||
// static utility class
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link IMonitoringServer} instance.
|
||||
*
|
||||
* @param componentId the component id
|
||||
* @param in the input stream used for accepting cli commands
|
||||
* @param out the output stream to print to
|
||||
* @return a new MonitoringServer instance
|
||||
*/
|
||||
public static IMonitoringServer createMonitoringServer(String componentId, InputStream in, PrintStream out)
|
||||
throws Exception {
|
||||
/*
|
||||
* TODO: Here you can modify the code (if necessary) to instantiate your components
|
||||
*/
|
||||
|
||||
Config config = new Config(componentId);
|
||||
return new MonitoringServer(componentId, config, in, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link IMailboxServer} instance.
|
||||
*
|
||||
* @param componentId the component id
|
||||
* @param in the input stream used for accepting cli commands
|
||||
* @param out the output stream to print to
|
||||
* @return a new MailboxServer instance
|
||||
*/
|
||||
public static IMailboxServer createMailboxServer(String componentId, InputStream in, PrintStream out)
|
||||
throws Exception {
|
||||
/*
|
||||
* TODO: Here you can modify the code (if necessary) to instantiate your components
|
||||
*/
|
||||
|
||||
Config config = new Config(componentId);
|
||||
return new MailboxServer(componentId, config, in, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ITransferServer} instance.
|
||||
*
|
||||
* @param componentId the component id
|
||||
* @param in the input stream used for accepting cli commands
|
||||
* @param out the output stream to print to
|
||||
* @return a new TransferServer instance
|
||||
*/
|
||||
public static ITransferServer createTransferServer(String componentId, InputStream in, PrintStream out)
|
||||
throws Exception {
|
||||
/*
|
||||
* TODO: Here you can modify the code (if necessary) to instantiate your components
|
||||
*/
|
||||
|
||||
Config config = new Config(componentId);
|
||||
return new TransferServer(componentId, config, in, out);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dslab.mailbox;
|
||||
|
||||
/**
|
||||
* The mailbox server receives mails via DMTP from transfer servers, and makes them available to users via the DMAP
|
||||
* protocol.
|
||||
*
|
||||
* Do not change the existing method signatures!
|
||||
*/
|
||||
public interface IMailboxServer extends Runnable {
|
||||
|
||||
/**
|
||||
* Starts the server.
|
||||
*/
|
||||
@Override
|
||||
void run();
|
||||
|
||||
/**
|
||||
* CLI command to shut down the server. After this method, all resources should be closed, and the application
|
||||
* should terminate.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package dslab.mailbox;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import dslab.ComponentFactory;
|
||||
import dslab.util.Config;
|
||||
|
||||
public class MailboxServer implements IMailboxServer, Runnable {
|
||||
|
||||
/**
|
||||
* Creates a new server instance.
|
||||
*
|
||||
* @param componentId the id of the component that corresponds to the Config resource
|
||||
* @param config the component config
|
||||
* @param in the input stream to read console input from
|
||||
* @param out the output stream to write console output to
|
||||
*/
|
||||
public MailboxServer(String componentId, Config config, InputStream in, PrintStream out) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
IMailboxServer server = ComponentFactory.createMailboxServer(args[0], System.in, System.out);
|
||||
server.run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package dslab.monitoring;
|
||||
|
||||
/**
|
||||
* The monitoring service accepts incoming monitoring packets via UDP. It provides CLI commands to access the
|
||||
* information.
|
||||
*
|
||||
* Do not change the existing method signatures!
|
||||
*/
|
||||
public interface IMonitoringServer extends Runnable {
|
||||
|
||||
/**
|
||||
* Starts the server.
|
||||
*/
|
||||
@Override
|
||||
void run();
|
||||
|
||||
/**
|
||||
* CLI command to shut down the server. After this method, all resources should be closed, and the application
|
||||
* should terminate.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* CLI command to report usage statistics for transfer servers.
|
||||
*/
|
||||
void servers();
|
||||
|
||||
/**
|
||||
* CLI command to report usage statistics for individual senders.
|
||||
*/
|
||||
void addresses();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package dslab.monitoring;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import dslab.ComponentFactory;
|
||||
import dslab.util.Config;
|
||||
|
||||
public class MonitoringServer implements IMonitoringServer {
|
||||
|
||||
/**
|
||||
* Creates a new server instance.
|
||||
*
|
||||
* @param componentId the id of the component that corresponds to the Config resource
|
||||
* @param config the component config
|
||||
* @param in the input stream to read console input from
|
||||
* @param out the output stream to write console output to
|
||||
*/
|
||||
public MonitoringServer(String componentId, Config config, InputStream in, PrintStream out) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addresses() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void servers() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
IMonitoringServer server = ComponentFactory.createMonitoringServer(args[0], System.in, System.out);
|
||||
server.run();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package dslab.transfer;
|
||||
|
||||
/**
|
||||
* The transfer server is responsible for accepting mails sent by users, and forward them to mailbox servers via DMTP.
|
||||
* It also reports usage statistics to the monitoring server.
|
||||
*
|
||||
* Do not change the existing method signatures!
|
||||
*/
|
||||
public interface ITransferServer extends Runnable {
|
||||
|
||||
/**
|
||||
* Starts the server.
|
||||
*/
|
||||
@Override
|
||||
void run();
|
||||
|
||||
/**
|
||||
* CLI command to shut down the server. After this method, all resources should be closed, and the application
|
||||
* should terminate.
|
||||
*/
|
||||
void shutdown();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package dslab.transfer;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import dslab.ComponentFactory;
|
||||
import dslab.util.Config;
|
||||
|
||||
public class TransferServer implements ITransferServer, Runnable {
|
||||
|
||||
/**
|
||||
* Creates a new server instance.
|
||||
*
|
||||
* @param componentId the id of the component that corresponds to the Config resource
|
||||
* @param config the component config
|
||||
* @param in the input stream to read console input from
|
||||
* @param out the output stream to write console output to
|
||||
*/
|
||||
public TransferServer(String componentId, Config config, InputStream in, PrintStream out) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ITransferServer server = ComponentFactory.createTransferServer(args[0], System.in, System.out);
|
||||
server.run();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package dslab.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Reads the configuration from a {@code .properties} file.
|
||||
*/
|
||||
public final class Config {
|
||||
|
||||
private final ResourceBundle bundle;
|
||||
private Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Creates an instance of Config which reads configuration data form {@code .properties} file with given name found
|
||||
* in classpath.
|
||||
*
|
||||
* @param name the name of the .properties file
|
||||
*/
|
||||
public Config(String name) {
|
||||
if (name.endsWith(".properties")) {
|
||||
this.bundle = ResourceBundle.getBundle(name.substring(0, name.length() - 11));
|
||||
} else {
|
||||
this.bundle = ResourceBundle.getBundle(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value as String for the given key.
|
||||
*
|
||||
* @param key the property's key
|
||||
* @return String value of the property
|
||||
* @see ResourceBundle#getString(String)
|
||||
*/
|
||||
public String getString(String key) {
|
||||
if (properties.containsKey(key)) {
|
||||
return properties.get(key).toString();
|
||||
}
|
||||
return this.bundle.getString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value as {@code int} for the given key.
|
||||
*
|
||||
* @param key the property's key
|
||||
* @return int value of the property
|
||||
* @throws NumberFormatException if the String cannot be parsed to an Integer
|
||||
*/
|
||||
public int getInt(String key) {
|
||||
return Integer.parseInt(getString(key));
|
||||
}
|
||||
|
||||
public boolean containsKey(String key) {
|
||||
return properties.containsKey(key) || bundle.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for the given key.
|
||||
*
|
||||
* @param key the property's key
|
||||
* @param value the value of the property
|
||||
*/
|
||||
public void setProperty(String key, Object value) {
|
||||
properties.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all keys of this configuration.
|
||||
*
|
||||
* @return the keys
|
||||
*/
|
||||
public Set<String> listKeys() {
|
||||
Set<String> keys = bundle.keySet();
|
||||
keys.addAll(properties.keySet());
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# <domain>=<socket-address>
|
||||
# TODO: replace ports with the ports that your mailbox servers use
|
||||
earth.planet=127.0.0.1:port_range+2
|
||||
univer.ze=127.0.0.1:port_range+4
|
||||
@@ -0,0 +1,25 @@
|
||||
# TCP port used for the DMTP server socket
|
||||
# TODO: REPLACE with real value such as 16502 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
dmtp.tcp.port=port_range+2
|
||||
|
||||
# TCP port used for the DMAP server socket
|
||||
# TODO: REPLACE with real value such as 16503 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
dmap.tcp.port=port_range+3
|
||||
|
||||
# mail domain managed by the mailbox server
|
||||
domain=earth.planet
|
||||
|
||||
# location of the users for this mailbox server
|
||||
users.config=users-earth-planet.properties
|
||||
|
||||
# ============================================= Required for Assignment 2
|
||||
|
||||
# name of the root nameserver's remote object
|
||||
root_id=root-nameserver
|
||||
|
||||
# RMI registry host
|
||||
registry.host=localhost
|
||||
|
||||
# RMI registry port
|
||||
# TODO: REPLACE with real value such as 16509 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
registry.port=port_range+9
|
||||
@@ -0,0 +1,25 @@
|
||||
# TCP port used for the DMTP server socket
|
||||
# TODO: REPLACE with real value such as 16504 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
dmtp.tcp.port=port_range+4
|
||||
|
||||
# TCP port used for the DMAP server socket
|
||||
# TODO: REPLACE with real value such as 16505 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
dmap.tcp.port=port_range+5
|
||||
|
||||
# mail domain managed by the mailbox server
|
||||
domain=univer.ze
|
||||
|
||||
# location of the users for this mailbox server
|
||||
users.config=users-univer-ze.properties
|
||||
|
||||
# ============================================= Required for Assignment 2
|
||||
|
||||
# name of the root nameserver's remote object
|
||||
root_id=root-nameserver
|
||||
|
||||
# RMI registry host
|
||||
registry.host=localhost
|
||||
|
||||
# RMI registry port
|
||||
# TODO: REPLACE with real value such as 16509 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
registry.port=port_range+9
|
||||
@@ -0,0 +1,3 @@
|
||||
# UDP port used for accepting monitoring packets
|
||||
# TODO: REPLACE with real value such as 16508 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
udp.port=port_range+8
|
||||
@@ -0,0 +1,20 @@
|
||||
# TCP port used for the DMTP server socket
|
||||
# TODO: REPLACE with real value such as 16500 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
tcp.port=port_range
|
||||
|
||||
# UDP socket address of the monitoring server
|
||||
monitoring.host=127.0.0.1
|
||||
# TODO: REPLACE with the real value of the monitoring server port
|
||||
monitoring.port=port_range+8
|
||||
|
||||
# ============================================= Required for Assignment 2
|
||||
|
||||
# name of the root nameserver's remote object
|
||||
root_id=root-nameserver
|
||||
|
||||
# RMI registry host
|
||||
registry.host=localhost
|
||||
|
||||
# RMI registry port
|
||||
# TODO: REPLACE with real value such as 16509 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
registry.port=port_range+9
|
||||
@@ -0,0 +1,20 @@
|
||||
# TCP port used for the DMTP server socket
|
||||
# TODO: REPLACE with real value such as 16501 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
tcp.port=port_range+1
|
||||
|
||||
# UDP socket address of the monitoring server
|
||||
monitoring.host=127.0.0.1
|
||||
# TODO: REPLACE with the real value of the monitoring server port
|
||||
monitoring.port=port_range+8
|
||||
|
||||
# ============================================= Required for Assignment 2
|
||||
|
||||
# name of the root nameserver's remote object
|
||||
root_id=root-nameserver
|
||||
|
||||
# RMI registry host
|
||||
registry.host=localhost
|
||||
|
||||
# RMI registry port
|
||||
# TODO: REPLACE with real value such as 16509 - considering the port range associated with your account - you have received after Lab 0 a port range (beginning_of_the_range, end_of_the_range)
|
||||
registry.port=port_range+9
|
||||
@@ -0,0 +1,3 @@
|
||||
# <username>=<password>
|
||||
trillian=12345
|
||||
arthur=23456
|
||||
@@ -0,0 +1,2 @@
|
||||
# <username>=<password>
|
||||
zaphod=12345
|
||||
Reference in New Issue
Block a user