Skip to content

Commit

Permalink
work on admin console
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Mar 17, 2008
1 parent e474436 commit 61d7379
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 40 deletions.
@@ -0,0 +1,36 @@
package org.jumpmind.symmetric;

import org.jumpmind.symmetric.db.IDbDialect;

public class ActivityListenerSupport implements IActivityListener {

public boolean createConfigurationTables(IDbDialect dbDialect) {
return true;
}

public boolean upgradeNeeded(String oldVersion, String newVersion) {
return false;
}

public void dataBatchReceived(DataEvent event) {
}

public void dataBatchSent(DataEvent event) {
}

public void loaded() {
}

public void nodeRegistered(String nodeId) {
}

public void registered() {
}

public void registrationOpened(String nodeId) {
}

public void tablesCreated() {
}

}
Expand Up @@ -19,9 +19,19 @@
*/
package org.jumpmind.symmetric;

import org.jumpmind.symmetric.db.IDbDialect;


/**
* This interface allows the SymmetricDS end user interact with the SymmetricDS engine in response to
* events within the system.
*/
public interface IActivityListener {

public boolean createConfigurationTables(IDbDialect dbDialect);

public boolean upgradeNeeded(String oldVersion, String newVersion);

public void tablesCreated();
public void registered();
public void loaded();
Expand Down
Expand Up @@ -99,30 +99,34 @@ public SymmetricEngine(String overridePropertiesResource1,
overridePropertiesResource1 == null ? "" : overridePropertiesResource1);
System.setProperty("symmetric.override.properties.file.2",
overridePropertiesResource2 == null ? "" : overridePropertiesResource2);
this.init(createContext());
this.init(createContext(), null);
}
}

/**
* Create a symmetric node
*/
public SymmetricEngine() {
init(createContext());
init(createContext(), null);
}

public SymmetricEngine(IActivityListener activityListener) {
init(createContext(), activityListener);
}

/**
* Pass in the Spring context to be used. This had better include the Spring configuration for required Symmetric services.
* @param ctx A Spring framework context
*/
protected SymmetricEngine(ApplicationContext ctx) {
init(ctx);
init(ctx, null);
}

private ApplicationContext createContext() {
return new ClassPathXmlApplicationContext("classpath:/symmetric.xml");
}

private void init(ApplicationContext applicationContext) {
private void init(ApplicationContext applicationContext, IActivityListener activityListener) {
this.applicationContext = applicationContext;
properties = (Properties) applicationContext
.getBean(Constants.PROPERTIES);
Expand All @@ -137,10 +141,17 @@ private void init(ApplicationContext applicationContext) {
purgeService = (IPurgeService) applicationContext
.getBean(Constants.PURGE_SERVICE);
dataService = (IDataService)applicationContext.getBean(Constants.DATA_SERVICE);
dbDialect = (IDbDialect)applicationContext.getBean(Constants.DB_DIALECT);
dbDialect = (IDbDialect) applicationContext.getBean(Constants.DB_DIALECT);
registerActivityListener(activityListener);
registerEngine();
logger.info("Initialized SymmetricDS externalId=" + runtimeConfig.getExternalId() + " version=" + Version.version() + " database="+dbDialect.getName());
}

private void registerActivityListener(IActivityListener listener) {
if (listener != null) {
bootstrapService.setActivityListener(listener);
}
}

/**
* Register this instance of the engine so it can be found by other processes in the JVM.
Expand Down
Expand Up @@ -114,18 +114,17 @@ public void actionPerformed(ActionEvent e) {
if (c != null && this.getValue(Action.NAME).equals(CONNECT)) {
try {
tree.setCursor(new Cursor(Cursor.WAIT_CURSOR));
Worker.post(new Task() {
if ((Boolean) Worker.post(new Task() {
public Object run() throws Exception {
c.getSymmetricDatabase().connect();
return null;
return c.getSymmetricDatabase().connect(appController);
}
});

DatabaseNode db = (DatabaseNode) c;
db.add(new ChannelNode(c.getSymmetricDatabase()));
db.add(new GroupNode(c.getSymmetricDatabase()));
db.add(new GroupLinkNode(c.getSymmetricDatabase()));
tree.scrollPathToVisible(new TreePath(db));
})) {
DatabaseNode db = (DatabaseNode) c;
db.add(new ChannelNode(c.getSymmetricDatabase()));
db.add(new GroupNode(c.getSymmetricDatabase()));
db.add(new GroupLinkNode(c.getSymmetricDatabase()));
tree.scrollPathToVisible(new TreePath(db));
}
} catch (Exception ex) {
appController.showError("Trouble connecting to the symmetric database.", ex);
}
Expand Down
Expand Up @@ -26,8 +26,12 @@

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;

public class AppFrame extends JFrame implements IAppController {
Expand Down Expand Up @@ -68,6 +72,10 @@ private void addScreenToPanel(AbstractScreen screen) {
}

public void showError(String message, Exception ex) {
JTextArea m = new JTextArea(10, 50);
m.setLineWrap(true);
m.setText(message);
JOptionPane.showMessageDialog(this, new JScrollPane(m), "", JOptionPane.ERROR_MESSAGE);
logger.error(message, ex);
}

Expand Down
Expand Up @@ -39,6 +39,8 @@

public class ConnectionDialog extends JPanel {

private static final String DEFAULT_TABLE_PREFIX = "sym";

private static final String MY_SYMMETRIC = "My Symmetric";

private static final long serialVersionUID = -4325767568474807143L;
Expand All @@ -54,6 +56,10 @@ public class ConnectionDialog extends JPanel {
JLabel passwordLabel;

JTextField passwordField;

JLabel tablePrefixLabel;

JTextField tablePrefixField;

JLabel urlLabel;

Expand All @@ -80,6 +86,9 @@ public ConnectionDialog() {

nameLabel = new JLabel("Connection name: ", JLabel.RIGHT);
nameField = new JTextField(MY_SYMMETRIC);

tablePrefixLabel = new JLabel("SymmmetricDS table prefix:", JLabel.RIGHT);
tablePrefixField = new JTextField(DEFAULT_TABLE_PREFIX);

userNameLabel = new JLabel("User name: ", JLabel.RIGHT);
userNameField = new JTextField("");
Expand All @@ -106,6 +115,7 @@ public void actionPerformed(ActionEvent e) {
JPanel namePanel = new JPanel(false);
namePanel.setLayout(new GridLayout(0, 1));
namePanel.add(nameLabel);
namePanel.add(tablePrefixLabel);
namePanel.add(driverLabel);
namePanel.add(urlLabel);
namePanel.add(userNameLabel);
Expand All @@ -114,6 +124,7 @@ public void actionPerformed(ActionEvent e) {
JPanel fieldPanel = new JPanel(false);
fieldPanel.setLayout(new GridLayout(0, 1));
fieldPanel.add(nameField);
fieldPanel.add(tablePrefixField);
fieldPanel.add(driverField);
fieldPanel.add(urlField);
fieldPanel.add(userNameField);
Expand All @@ -133,6 +144,7 @@ private void resetDialog() {
}
driverField.setSelectedIndex(0);
nameField.setText(MY_SYMMETRIC);
tablePrefixField.setText(DEFAULT_TABLE_PREFIX);
}

public SymmetricDatabase activateConnectionDialog(Component parent, SymmetricDatabase db) {
Expand Down
Expand Up @@ -36,6 +36,8 @@ public class InfoScreen extends AbstractScreen {

private JLabel databaseName;

private JLabel tablePrefix;

private JLabel userName;

private JLabel driverName;
Expand All @@ -50,7 +52,7 @@ protected InfoScreen() {
databaseInfoPanel.setMinimumSize(new Dimension(500, 100));
databaseInfoPanel.setBorder(new TitledBorder("Server Info"));

double size[][] = { { 5, 100, TableLayout.FILL }, { 5, 20, 20, 20, 20, 5 } };
double size[][] = { { 5, 100, TableLayout.FILL }, { 5, 20, 20, 20, 20, 20, 5 } };

TableLayout layout = new TableLayout(size);
databaseInfoPanel.setLayout(layout);
Expand All @@ -62,21 +64,26 @@ protected InfoScreen() {
databaseName = new JLabel();
databaseName.setEnabled(false);
databaseInfoPanel.add(databaseName, "2,1");

databaseInfoPanel.add(new JLabel("Table Prefix: "), "1,2");
tablePrefix = new JLabel();
tablePrefix.setEnabled(false);
databaseInfoPanel.add(tablePrefix, "2,2");

databaseInfoPanel.add(new JLabel("Jdbc Url: "), "1,2");
databaseInfoPanel.add(new JLabel("Jdbc Url: "), "1,3");
jdbcUrl = new JLabel();
jdbcUrl.setEnabled(false);
databaseInfoPanel.add(jdbcUrl, "2,2");
databaseInfoPanel.add(jdbcUrl, "2,3");

databaseInfoPanel.add(new JLabel("Driver Name: "), "1,3");
databaseInfoPanel.add(new JLabel("Driver Name: "), "1,4");
driverName = new JLabel();
driverName.setEnabled(false);
databaseInfoPanel.add(driverName, "2,3");
databaseInfoPanel.add(driverName, "2,4");

databaseInfoPanel.add(new JLabel("User Name: "), "1,4");
databaseInfoPanel.add(new JLabel("User Name: "), "1,5");
userName = new JLabel();
userName.setEnabled(false);
databaseInfoPanel.add(userName, "2,4");
databaseInfoPanel.add(userName, "2,5");

JPanel bottomStrut = new JPanel();
bottomStrut.setPreferredSize(new Dimension(100, 500));
Expand All @@ -89,6 +96,7 @@ public void setup(SymmetricDatabase c) {
driverName.setText(c.getDriverName());
databaseName.setText(c.getName());
userName.setText(c.getUserName());
tablePrefix.setText(c.getTablePrefix());
this.repaint();
}

Expand Down
Expand Up @@ -22,9 +22,15 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.swing.JOptionPane;

import org.jumpmind.symmetric.ActivityListenerSupport;
import org.jumpmind.symmetric.SymmetricEngine;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.PropertiesConstants;
import org.jumpmind.symmetric.db.IDbDialect;
import org.jumpmind.symmetric.model.NodeChannel;
import org.jumpmind.symmetric.service.IConfigurationService;

Expand All @@ -41,8 +47,12 @@ public class SymmetricDatabase implements Serializable {
private String password;

private String driverName;


private String tablePrefix = "sym";

private transient SymmetricEngine engine;

private transient IAppController controller;

public SymmetricDatabase() {
}
Expand All @@ -56,26 +66,53 @@ public String getJdbcUrl() {
return jdbcUrl;
}

public void connect() {
public boolean connect(IAppController c) {
this.controller = c;
try {
synchronized (SymmetricDatabase.class) {
System.setProperty("db.url", jdbcUrl);
System.setProperty("db.driver", driverName);
System.setProperty("db.user", username == null ? "" : username);
System.setProperty("db.password", password == null ? "" : password);
System.setProperty("db.pool.initial.size", "1");
engine = new SymmetricEngine();
System.setProperty(PropertiesConstants.DBPOOL_URL, jdbcUrl);
System.setProperty(PropertiesConstants.DBPOOL_DRIVER, driverName);
System.setProperty(PropertiesConstants.DBPOOL_USER, username == null ? "" : username);
System.setProperty(PropertiesConstants.DBPOOL_URL, password == null ? "" : password);
System.setProperty(PropertiesConstants.DBPOOL_INITIAL_SIZE, "1");
System.setProperty(PropertiesConstants.RUNTIME_CONFIG_TABLE_PREFIX, tablePrefix);
System.setProperty(PropertiesConstants.START_HEARTBEAT_JOB, Boolean.toString(false));
System.setProperty(PropertiesConstants.START_SYNCTRIGGERS_JOB, Boolean.toString(false));
System.setProperty(PropertiesConstants.START_PUSH_JOB, Boolean.toString(false));
System.setProperty(PropertiesConstants.START_PURGE_JOB, Boolean.toString(false));
System.setProperty(PropertiesConstants.START_PULL_JOB, Boolean.toString(false));
engine = new SymmetricEngine(new ActivityListenerSupport() {
@Override
public boolean createConfigurationTables(IDbDialect dbDialect) {
if (dbDialect.doesDatabaseNeedConfigured()) {
if (
JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(controller.getFrame(), "Configuration tables need to be created. Is it OK to proceed?", "Create Tables?", JOptionPane.YES_NO_OPTION)) {
throw new RuntimeException("SymmetricDS is not configured. Please configure the database before connecting.");
}
}
return true;
}
});
engine.start();
return true;
}
} catch (Exception ex) {
engine = null;
controller.showError(ex.getMessage(), ex);
return false;
}
}

public List<NodeChannel> getChannels() {
if (engine != null) {
IConfigurationService configService = (IConfigurationService)engine.getApplicationContext().getBean(Constants.CONFIG_SERVICE);
IConfigurationService configService = (IConfigurationService) engine.getApplicationContext().getBean(
Constants.CONFIG_SERVICE);
return configService.getChannelsFor(true);
} else {
return new ArrayList<NodeChannel>(0);
}
}

public void disconnect() {
// TODO
}
Expand Down Expand Up @@ -125,4 +162,12 @@ public String toString() {
return name;
}

public String getTablePrefix() {
return tablePrefix;
}

public void setTablePrefix(String tablePrefix) {
this.tablePrefix = tablePrefix;
}

}

0 comments on commit 61d7379

Please sign in to comment.