richie
6 years ago
17 changed files with 569 additions and 65 deletions
@ -0,0 +1,15 @@
|
||||
package com.fr.plugin.db.redis.core.emb; |
||||
|
||||
import com.fr.third.redis.clients.jedis.Jedis; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-03-21 |
||||
*/ |
||||
public interface Redis { |
||||
|
||||
Jedis getClient(); |
||||
|
||||
void close(); |
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.fr.plugin.db.redis.core.emb.impl; |
||||
|
||||
import com.fr.plugin.db.redis.core.emb.Redis; |
||||
import com.fr.ssh.jsch.Session; |
||||
import com.fr.third.redis.clients.jedis.Jedis; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-03-21 |
||||
*/ |
||||
public class ProxyRedis implements Redis { |
||||
|
||||
private Session session; |
||||
private Jedis jedis; |
||||
|
||||
public ProxyRedis(Session session, Jedis jedis) { |
||||
this.session = session; |
||||
this.jedis = jedis; |
||||
} |
||||
|
||||
@Override |
||||
public Jedis getClient() { |
||||
return jedis; |
||||
} |
||||
|
||||
@Override |
||||
public void close() { |
||||
jedis.close(); |
||||
session.disconnect(); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fr.plugin.db.redis.core.emb.impl; |
||||
|
||||
import com.fr.plugin.db.redis.core.emb.Redis; |
||||
import com.fr.third.redis.clients.jedis.Jedis; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-03-21 |
||||
*/ |
||||
public class SimpleRedis implements Redis { |
||||
|
||||
private Jedis jedis; |
||||
|
||||
public SimpleRedis(Jedis jedis) { |
||||
this.jedis = jedis; |
||||
} |
||||
|
||||
@Override |
||||
public Jedis getClient() { |
||||
return jedis; |
||||
} |
||||
|
||||
@Override |
||||
public void close() { |
||||
jedis.close(); |
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
package com.fr.plugin.db.redis.core.pool; |
||||
|
||||
import com.fr.config.ConfigContext; |
||||
import com.fr.config.DefaultConfiguration; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-03-21 |
||||
*/ |
||||
public class RedisConnectionPoolConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile RedisConnectionPoolConfig instance = null; |
||||
|
||||
public static RedisConnectionPoolConfig getInstance() { |
||||
if (instance == null) { |
||||
instance = ConfigContext.getConfigInstance(RedisConnectionPoolConfig.class); |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
private static final int MAX_TOTAL = 10; |
||||
private static final int MAX_WAIT = -1; |
||||
|
||||
private Conf<Integer> maxTotal = Holders.simple(MAX_TOTAL); |
||||
private Conf<Integer> maxWait = Holders.simple(MAX_WAIT); |
||||
|
||||
public int getMaxTotal() { |
||||
return maxTotal.get(); |
||||
} |
||||
|
||||
public void setMaxTotal(Integer maxTotal) { |
||||
this.maxTotal.set(maxTotal); |
||||
} |
||||
|
||||
public int getMaxWait() { |
||||
return maxWait.get(); |
||||
} |
||||
|
||||
public void setMaxWait(int maxWait) { |
||||
this.maxWait.set(maxWait); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
RedisConnectionPoolConfig cloned = (RedisConnectionPoolConfig) super.clone(); |
||||
cloned.maxTotal = (Conf<Integer>) maxTotal.clone(); |
||||
cloned.maxWait = (Conf<Integer>) maxWait.clone(); |
||||
return cloned; |
||||
} |
||||
} |
@ -0,0 +1,97 @@
|
||||
package com.fr.plugin.db.redis.core.pool; |
||||
|
||||
import com.fr.config.ConfigContext; |
||||
import com.fr.config.DefaultConfiguration; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-03-21 |
||||
*/ |
||||
public class RedisConnectionProxyConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile RedisConnectionProxyConfig instance = null; |
||||
|
||||
public static RedisConnectionProxyConfig getInstance() { |
||||
if (instance == null) { |
||||
instance = ConfigContext.getConfigInstance(RedisConnectionProxyConfig.class); |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
private Conf<Boolean> open = Holders.simple(false); |
||||
|
||||
private Conf<String> host = Holders.simple(StringUtils.EMPTY); |
||||
|
||||
private Conf<Integer> port = Holders.simple(22); |
||||
|
||||
private Conf<String> username = Holders.simple(StringUtils.EMPTY); |
||||
|
||||
private Conf<String> password = Holders.simple(StringUtils.EMPTY); |
||||
|
||||
private Conf<String> privateKeyPath = Holders.simple(StringUtils.EMPTY); |
||||
|
||||
|
||||
public boolean isOpen() { |
||||
return open.get(); |
||||
} |
||||
|
||||
public void setOpen(boolean open) { |
||||
this.open.set(open); |
||||
} |
||||
|
||||
public String getHost() { |
||||
return host.get(); |
||||
} |
||||
|
||||
public void setHost(String host) { |
||||
this.host.set(host); |
||||
} |
||||
|
||||
public int getPort() { |
||||
return port.get(); |
||||
} |
||||
|
||||
public void setPort(int port) { |
||||
this.port.set(port); |
||||
} |
||||
|
||||
public String getUsername() { |
||||
return username.get(); |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
this.username.set(username); |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password.get(); |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password.set(password); |
||||
} |
||||
|
||||
public String getPrivateKeyPath() { |
||||
return privateKeyPath.get(); |
||||
} |
||||
|
||||
public void setPrivateKeyPath(String privateKeyPath) { |
||||
this.privateKeyPath.set(privateKeyPath); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
RedisConnectionProxyConfig cloned = (RedisConnectionProxyConfig) super.clone(); |
||||
cloned.open = (Conf<Boolean>) open.clone(); |
||||
cloned.host = (Conf<String>) host.clone(); |
||||
cloned.port = (Conf<Integer>) port.clone(); |
||||
cloned.username = (Conf<String>) username.clone(); |
||||
cloned.password = (Conf<String>) password.clone(); |
||||
cloned.privateKeyPath = (Conf<String>) privateKeyPath.clone(); |
||||
return cloned; |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.plugin.db.redis.ui.pool; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itextfield.UIIntNumberField; |
||||
import com.fr.design.gui.itextfield.UINumberField; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.plugin.db.redis.core.pool.RedisConnectionPoolConfig; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-03-21 |
||||
*/ |
||||
public class RedisConnectionPoolConfigPane extends BasicPane { |
||||
|
||||
private UIIntNumberField maxTotalNumberFiled; |
||||
private UINumberField maxWaitNumberField; |
||||
|
||||
public RedisConnectionPoolConfigPane() { |
||||
setLayout(new BorderLayout()); |
||||
maxTotalNumberFiled = new UIIntNumberField(); |
||||
maxWaitNumberField = new UINumberField(); |
||||
maxWaitNumberField.setMinValue(-1); |
||||
maxWaitNumberField.setMaxDecimalLength(0); |
||||
JComponent[][] comps = new JComponent[][]{ |
||||
{new UILabel(Toolkit.i18nText("Plugin-Redis_Pool_Max_Total") + ":"), maxTotalNumberFiled}, |
||||
{new UILabel(Toolkit.i18nText("Plugin-Redis_Pool_Max_Wait") + ":"), maxWaitNumberField} |
||||
}; |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
|
||||
double[] rowSize = new double[]{p, p}; |
||||
double[] columnSize = new double[]{p, f}; |
||||
add(TableLayoutHelper.createTableLayoutPane(comps, rowSize, columnSize), BorderLayout.CENTER); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Toolkit.i18nText("Plugin-Redis_Pool_Config"); |
||||
} |
||||
|
||||
public void populate(RedisConnectionPoolConfig config) { |
||||
maxTotalNumberFiled.setValue(config.getMaxTotal()); |
||||
maxWaitNumberField.setValue(config.getMaxWait()); |
||||
} |
||||
|
||||
public void update(RedisConnectionPoolConfig config) { |
||||
config.setMaxTotal((int)maxTotalNumberFiled.getValue()); |
||||
config.setMaxWait((int) maxWaitNumberField.getValue()); |
||||
} |
||||
} |
@ -0,0 +1,107 @@
|
||||
package com.fr.plugin.db.redis.ui.proxy; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ipasswordfield.UIPassWordField; |
||||
import com.fr.design.gui.itextfield.UIIntNumberField; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.plugin.db.redis.core.pool.RedisConnectionProxyConfig; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.io.File; |
||||
|
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-03-21 |
||||
*/ |
||||
public class RedisConnectionProxyConfigPane extends BasicPane { |
||||
|
||||
private UICheckBox openCheckBox; |
||||
private UITextField hostTextField; |
||||
private UIIntNumberField portNumberField; |
||||
private UITextField usernameTextField; |
||||
private UIPassWordField passwordTextField; |
||||
private UITextField privateKeyPathTextField; |
||||
|
||||
public RedisConnectionProxyConfigPane() { |
||||
setLayout(new BorderLayout()); |
||||
|
||||
openCheckBox = new UICheckBox(); |
||||
openCheckBox.setSelected(false); |
||||
|
||||
hostTextField = new UITextField(); |
||||
portNumberField = new UIIntNumberField(); |
||||
usernameTextField = new UITextField(); |
||||
passwordTextField = new UIPassWordField(); |
||||
|
||||
privateKeyPathTextField = new UITextField(); |
||||
privateKeyPathTextField.setPlaceholder(Toolkit.i18nText("Plugin-Redis_Proxy_Private_Key_Tip")); |
||||
|
||||
UIButton fileSelectButton = new UIButton("..."); |
||||
|
||||
JComponent[][] comps = new JComponent[][]{ |
||||
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Open") + ":"), openCheckBox}, |
||||
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Host") + ":"), hostTextField}, |
||||
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Port") + ":"), portNumberField}, |
||||
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Username") + ":"), usernameTextField}, |
||||
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Password") + ":"), passwordTextField}, |
||||
{new UILabel(Toolkit.i18nText("Plugin-Redis_Proxy_Private_Key_Path") + ":"), GUICoreUtils.createBorderLayoutPane( |
||||
privateKeyPathTextField, BorderLayout.CENTER, |
||||
fileSelectButton, BorderLayout.EAST |
||||
)}, |
||||
}; |
||||
fileSelectButton.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
JFileChooser chooser = new JFileChooser(); |
||||
chooser.showOpenDialog(SwingUtilities.getWindowAncestor(RedisConnectionProxyConfigPane.this)); |
||||
File file = chooser.getSelectedFile(); |
||||
if (file != null) { |
||||
privateKeyPathTextField.setText(file.getAbsolutePath()); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
|
||||
double[] rowSize = new double[]{p, p, p, p, p, p}; |
||||
double[] columnSize = new double[]{p, f}; |
||||
add(TableLayoutHelper.createTableLayoutPane(comps, rowSize, columnSize), BorderLayout.CENTER); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Toolkit.i18nText("Plugin-Redis_Proxy_Config"); |
||||
} |
||||
|
||||
public void populate(RedisConnectionProxyConfig config) { |
||||
openCheckBox.setSelected(config.isOpen()); |
||||
hostTextField.setText(config.getHost()); |
||||
portNumberField.setValue(config.getPort()); |
||||
usernameTextField.setText(config.getUsername()); |
||||
passwordTextField.setText(config.getPassword()); |
||||
privateKeyPathTextField.setText(config.getPrivateKeyPath()); |
||||
} |
||||
|
||||
public void update(RedisConnectionProxyConfig config) { |
||||
config.setOpen(openCheckBox.isSelected()); |
||||
config.setHost(hostTextField.getText()); |
||||
config.setPort((int) portNumberField.getValue()); |
||||
config.setUsername(usernameTextField.getText()); |
||||
config.setPassword(passwordTextField.getText()); |
||||
config.setPrivateKeyPath(privateKeyPathTextField.getText()); |
||||
} |
||||
} |
Loading…
Reference in new issue