Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.rmi.*;
- public interface KMeans extends Remote {
- VectorSerializable[] getClusters() throws RemoteException;
- }
- ----------------------
- import java.io.Serializable;
- import java.rmi.*;
- import java.rmi.server.*;
- import java.sql.*;
- import dbkmeans.*;
- public class KMeansImpl extends UnicastRemoteObject implements KMeans, Serializable {
- private static final long serialVersionUID = 1L;
- private String nome;
- public KMeansImpl(String n) throws RemoteException {
- nome = n;
- }
- public VectorSerializable[] getClusters() throws RemoteException {
- VectorSerializable dataPoints = new VectorSerializable();
- Connection con = null;
- Statement stmt = null;
- ResultSet rs = null;
- VectorSerializable[] v = null;
- try{
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection("jdbc:mysql://localhost/SEI?user=root&password=d4t4b4s3");
- System.out.println("Connessione al DB SEI Riuscita");
- stmt = con.createStatement();
- rs = stmt.executeQuery("select * from giocatori");
- while (rs.next()) {
- String nome = rs.getString("Nome_giocatore");
- int prezzo = rs.getInt("Prezzo");
- dataPoints.add(new DataPoint(0, prezzo, nome));
- }
- System.out.println("Sono arrivato fin qui.");
- JCA jca = new JCA(3, 1000, dataPoints);
- jca.startAnalysis();
- v = jca.getClusterOutput();
- System.out.println("Ora fin arrivato fin qui.");
- System.out.println("Taglia: "+v.length);
- }
- catch(Exception e){
- System.out.println("Connessione al DB SEI Rifiutata");
- System.exit(0);
- }
- return v;
- }
- public static void main(String[] args) {
- try {
- KMeansImpl km1 = new KMeansImpl("KMeans1");
- Naming.rebind("KMeans1", km1);
- System.out.println("Attesa Client...");
- }
- catch(Exception e) { e.printStackTrace(); }
- }
- }
- ----------------------
- import java.rmi.*;
- import java.util.Iterator;
- import dbkmeans.DataPoint;
- public class Client {
- public static void main(String[] args) {
- try {
- System.out.println("Provo la connessione\n");
- KMeans km1 = (KMeans) Naming.lookup("rmi://localhost/KMeans1");
- System.out.println("Chiedo il vector\n");
- VectorSerializable[] v = km1.getClusters();
- System.out.println("Ho ricevuto il vector\n");
- for (int i = 0; i < v.length; i++) {
- VectorSerializable tempV = v[i];
- System.out.println("-----------Cluster" + i + "-----------");
- Iterator iter = tempV.iterator();
- while (iter.hasNext()) {
- DataPoint dpTemp = (DataPoint) iter.next();
- System.out.println(dpTemp.getObjName() + "[" + dpTemp.getX() + "," + dpTemp.getY() + "]");
- }
- }
- } catch(Exception e) { e.printStackTrace(); }
- }
- }
- ----------------------
- import java.io.Serializable;
- import java.util.Vector;
- public class VectorSerializable extends Vector implements Serializable {
- }
Add Comment
Please, Sign In to add comment