Custom connection pool with Java

I created this very simple connection pool in Java using the factory pattern. My idea here was to try 2 connection types, SQL and NoSQL. Please check and suggest if my approach is ok. I'm trying Java design samples, so based on your assessment, I can determine where I need to improve my design process.

public interface Connection {

    UUID getMarker();
    boolean commit();
    void close();

} 


public class JdbcConnection implements Connection {

    private Credentials credentials;
    private HostInfo hostInfo;
    private UUID marker;

    public JdbcConnection(UUID marker, Credentials credentials, HostInfo hostInfo) {
        this.credentials = credentials;
        this.hostInfo = hostInfo;
        this.marker = marker;
    }

    public UUID getMarker() {
        return marker;
    }

    public boolean commit() {
        return true;
    }

    public void close() {
        System.out.println("("+ this.marker+ ") is closed, and New UUID Issued");
        this.marker = UUID.randomUUID();
    }
}


public final class ConnectionFactory {

    private ConnectionFactory() {
    }

    public static Connection get(ConnectionType type, DbPoolconfig dbPoolconfig) {
        if (type.equals(ConnectionType.SQL)) {
            return new JdbcConnection(UUID.randomUUID(), dbPoolconfig.getCredentials(), dbPoolconfig.getHostInfo());
        }
        return new CassandraConnection(UUID.randomUUID(), dbPoolconfig.getCredentials(), dbPoolconfig.getHostInfo());

    }

}


public interface Pool {
    T get() throws InterruptedException;
    void release(T object);
    void shutdown();
}



public interface DbConnectionPool extends Pool {
    int getAvailableConnections();
    int getBusyConnectionsCount();
}

public final class DbConnectionPoolManager implements DbConnectionPool {

    private static DbConnectionPoolManager instance;
    private DbPoolconfig dbPoolconfig;
    private BlockingQueue pool;
    private Set busy;

    public static DbConnectionPoolManager get(DbPoolconfig dbPoolconfig) {
        if (instance == null) {
            synchronized (DbConnectionPoolManager.class) {
                if (instance == null) {
                    return new DbConnectionPoolManager(dbPoolconfig);
                }
            }
        }

        return instance;
    }

    private DbConnectionPoolManager(DbPoolconfig dbPoolconfig) {
        this.dbPoolconfig = dbPoolconfig;
        this.pool = new LinkedBlockingQueue(dbPoolconfig.getMaxSize());
        this.busy = new HashSet();
        init();
    }

    private void init() {

        int initial = dbPoolconfig.getIntialSize();
        for (int i = 0; i < initial; i++) {
            pool.offer(ConnectionFactory.get(dbPoolconfig.getType(), dbPoolconfig));
        }

    }

    public Connection createNew() {
        if (busy.size() == dbPoolconfig.getMaxSize()) {
            throw new RuntimeException("Pool is full.. cannot issue cnnectoon");
        }
        Connection connection = ConnectionFactory.get(dbPoolconfig.getType(), dbPoolconfig);
        pool.offer(connection);
        return connection;
    }

    public Connection get() throws InterruptedException {
        Connection connection = null;
        if (pool.peek() == null && busy.size() < dbPoolconfig.getMaxSize()) {
            connection = createNew();
        } else {
            connection = pool.take();
        }

        this.busy.add(connection);
        return connection;
    }

    public void release(Object object) {
        if (object != null) {
            Connection connection = (Connection) object;
            connection.close();
            pool.offer(connection);
            this.busy.remove(connection);
        }
    }

    public void shutdown() {
        // clear connection and remove from queu
        while (!pool.isEmpty()) {
            Connection connection = null;
            try {
                connection = pool.take();
                connection.close();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public int getAvailableConnections() {
        return (dbPoolconfig.getMaxSize() - busy.size());
    }

    public int getBusyConnectionsCount() {
        return busy.size();
    }

}

//Test
public class DbConnectionPooMangerTest {
    DbConnectionPoolManager mgr;

    @Before
    public void before() {
        Credentials credentials = new Credentials("1", "2");
        HostInfo info = new HostInfo("sss", "sss");
        DbPoolconfig config = new DbPoolconfig(info, credentials, ConnectionType.SQL, 15, 2);
        mgr = DbConnectionPoolManager.get(config);
    }

    @Test
    public void testConnection() {
        int m = 40;
        ExecutorService service = Executors.newFixedThreadPool(m);
        final List> conns = new ArrayList();

        Callable callable = new Callable() {
            public String call() throws Exception {
                try {
                    Connection con = mgr.get();
                    TimeUnit.SECONDS.sleep((long) (Math.random() * 2));
                    mgr.release(con);
                    System.out.println("Available "+ mgr.getAvailableConnections());
                    System.out.println("Busy "+ mgr.getBusyConnectionsCount());
                    return (con.getMarker()) +"";
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                return null;
            }
        };

        for (int i = 0; i < m; i++) {
            Future f = service.submit(callable);
             conns.add(f);
        }

        int count = 0;
        for(Future f : conns) {
            try {
                String s = f.get();
                System.out.println(s);
                if(s != null) {
                    count++;
                }
            }catch (Exception e) {
                e.printStackTrace();;
            }

        }

        Assert.assertEquals(m, count);
        service.shutdown();
    }
}

mariadb – Broken connection to the MySQL server during handshake after truncating the table

I used the latest version of Heidi SQL over an SSH tunnel to truncate a 2.5 GB table. If I clicked "Cut MSQL", the connection was immediately interrupted and it has not started since then, regardless of whether I restart the server.

I tried to look for a solution, everyone recommends disabling the firewall, which I did and didn't change anything.

When I try to start MYSQL, I get the following error message: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

Here is the output from systemctl status mariadb.service:

mariadb.service - MariaDB 10.2.30 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: failed (Result: exit-code) since Fri 2020-01-17 20:58:40 UTC; 4min 12s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 3484 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS --basedir=/usr $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
  Process: 3271 ExecStartPre=/bin/sh -c ( ! -e /usr/bin/galera_recovery ) && VAR= ||   VAR=`/usr/bin/galera_recovery`; ( $? -eq 0 )   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
  Process: 3268 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 3484 (code=exited, status=1/FAILURE)
   Status: "MariaDB server is down"

Jan 17 20:58:33 server-2 systemd(1): Starting MariaDB 10.2.30 database server...
Jan 17 20:58:34 server-2 mysqld(3484): 2020-01-17 20:58:34 140068938262720 (Note) /usr/sbin/mysqld (mysqld 10.2.30-MariaDB) starting as process 3484 ...
Jan 17 20:58:40 server-2 systemd(1): mariadb.service: main process exited, code=exited, status=1/FAILURE
Jan 17 20:58:40 server-2 systemd(1): Failed to start MariaDB 10.2.30 database server.
Jan 17 20:58:40 server-2 systemd(1): Unit mariadb.service entered failed state.
Jan 17 20:58:40 server-2 systemd(1): mariadb.service failed.

And the issue of journalctl -xe:

-- Subject: Unit session-6.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-6.scope has finished starting up.
--
-- The start-up result is done.
Jan 17 21:01:01 server-2 CROND(3798): (root) CMD (run-parts /etc/cron.hourly)
Jan 17 21:01:01 server-2 run-parts(/etc/cron.hourly)(3801): starting 0anacron
Jan 17 21:01:01 server-2 run-parts(/etc/cron.hourly)(3807): finished 0anacron
Jan 17 21:01:46 server-2 sshd(3896): reverse mapping checking getaddrinfo for test-whatup.inet.co.th (203.150.221.195) failed - POSSIBLE BREAK-IN ATTEMPT!
Jan 17 21:01:46 server-2 sshd(3896): pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=203.150.221.195  user=root
Jan 17 21:01:46 server-2 sshd(3896): pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
Jan 17 21:01:47 server-2 sshd(3900): Invalid user mao from 157.245.243.4 port 57002
Jan 17 21:01:47 server-2 sshd(3900): input_userauth_request: invalid user mao (preauth)
Jan 17 21:01:47 server-2 sshd(3900): pam_unix(sshd:auth): check pass; user unknown
Jan 17 21:01:47 server-2 sshd(3900): pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=157.245.243.4
Jan 17 21:01:48 server-2 sshd(3896): Failed password for root from 203.150.221.195 port 44978 ssh2
Jan 17 21:01:48 server-2 sshd(3896): Received disconnect from 203.150.221.195 port 44978:11: Bye Bye (preauth)
Jan 17 21:01:48 server-2 sshd(3896): Disconnected from 203.150.221.195 port 44978 (preauth)
Jan 17 21:01:49 server-2 sshd(3900): Failed password for invalid user mao from 157.245.243.4 port 57002 ssh2
Jan 17 21:01:49 server-2 sshd(3900): Received disconnect from 157.245.243.4 port 57002:11: Bye Bye (preauth)
Jan 17 21:01:49 server-2 sshd(3900): Disconnected from 157.245.243.4 port 57002 (preauth)
Jan 17 21:02:21 server-2 sshd(3958): Invalid user ts3 from 41.224.59.78 port 38484
Jan 17 21:02:21 server-2 sshd(3958): input_userauth_request: invalid user ts3 (preauth)
Jan 17 21:02:21 server-2 sshd(3958): pam_unix(sshd:auth): check pass; user unknown
Jan 17 21:02:21 server-2 sshd(3958): pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=41.224.59.78
Jan 17 21:02:23 server-2 sshd(3958): Failed password for invalid user ts3 from 41.224.59.78 port 38484 ssh2
Jan 17 21:02:23 server-2 sshd(3958): Received disconnect from 41.224.59.78 port 38484:11: Bye Bye (preauth)
Jan 17 21:02:23 server-2 sshd(3958): Disconnected from 41.224.59.78 port 38484 (preauth)
Jan 17 21:02:26 server-2 sshd(3965): Invalid user bill from 172.81.210.86 port 54268
Jan 17 21:02:26 server-2 sshd(3965): input_userauth_request: invalid user bill (preauth)
Jan 17 21:02:26 server-2 sshd(3965): pam_unix(sshd:auth): check pass; user unknown
Jan 17 21:02:26 server-2 sshd(3965): pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=172.81.210.86
Jan 17 21:02:28 server-2 sshd(3965): Failed password for invalid user bill from 172.81.210.86 port 54268 ssh2
Jan 17 21:02:28 server-2 sshd(3965): Received disconnect from 172.81.210.86 port 54268:11: Bye Bye (preauth)
Jan 17 21:02:28 server-2 sshd(3965): Disconnected from 172.81.210.86 port 54268 (preauth)
Jan 17 21:02:38 server-2 sshd(3979): Invalid user dropbox from 207.154.218.16 port 41892
Jan 17 21:02:38 server-2 sshd(3979): input_userauth_request: invalid user dropbox (preauth)
Jan 17 21:02:38 server-2 sshd(3979): pam_unix(sshd:auth): check pass; user unknown
Jan 17 21:02:38 server-2 sshd(3979): pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=207.154.218.16
Jan 17 21:02:39 server-2 sshd(3979): Failed password for invalid user dropbox from 207.154.218.16 port 41892 ssh2
Jan 17 21:02:39 server-2 sshd(3979): Received disconnect from 207.154.218.16 port 41892:11: Bye Bye (preauth)
Jan 17 21:02:39 server-2 sshd(3979): Disconnected from 207.154.218.16 port 41892 (preauth)
Jan 17 21:02:58 server-2 sshd(4028): reverse mapping checking getaddrinfo for d1-4-232-143-118-on-nets.com (118.143.232.4) failed - POSSIBLE BREAK-IN ATTEMPT!
Jan 17 21:02:58 server-2 sshd(4028): Invalid user rasa from 118.143.232.4 port 45328
Jan 17 21:02:58 server-2 sshd(4028): input_userauth_request: invalid user rasa (preauth)
Jan 17 21:02:58 server-2 sshd(4028): pam_unix(sshd:auth): check pass; user unknown
Jan 17 21:02:58 server-2 sshd(4028): pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=118.143.232.4
Jan 17 21:03:00 server-2 sshd(4028): Failed password for invalid user rasa from 118.143.232.4 port 45328 ssh2
Jan 17 21:03:00 server-2 sshd(4028): Received disconnect from 118.143.232.4 port 45328:11: Bye Bye (preauth)
Jan 17 21:03:00 server-2 sshd(4028): Disconnected from 118.143.232.4 port 45328 (preauth)
Jan 17 21:03:22 server-2 sshd(4075): pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=122.51.198.248  user=root
Jan 17 21:03:22 server-2 sshd(4075): pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
Jan 17 21:03:23 server-2 sshd(4075): Failed password for root from 122.51.198.248 port 35926 ssh2
Jan 17 21:03:23 server-2 sshd(4075): Received disconnect from 122.51.198.248 port 35926:11: Bye Bye (preauth)
Jan 17 21:03:23 server-2 sshd(4075): Disconnected from 122.51.198.248 port 35926 (preauth)
Jan 17 21:03:50 server-2 sshd(4127): pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=41.224.59.78  user=root
Jan 17 21:03:50 server-2 sshd(4127): pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
Jan 17 21:03:52 server-2 sshd(4127): Failed password for root from 41.224.59.78 port 51712 ssh2
Jan 17 21:03:53 server-2 sshd(4127): Received disconnect from 41.224.59.78 port 51712:11: Bye Bye (preauth)
Jan 17 21:03:53 server-2 sshd(4127): Disconnected from 41.224.59.78 port 51712 (preauth)

What is going on here, why did it happen and how can I fix it?

Network – Ethernet Disconnects the connection for a specific computer AND a specific socket frequently and temporarily

I have a specific problem with a specific desktop computer and a specific Ethernet wall socket. I've tried different approaches to fix the problem. Please read this post carefully as I describe it.

I have connected a desktop computer (details at the end of this article) to an Ethernet wall socket in my apartment. A few days ago I noticed that the internet was going to be interrupted for a short time. This was noticeable for the first time in a loss of video quality during streaming, but was also reflected in longer initial connection times when the computer was first switched on, regular changes to the network status icon and a disconnection from online gaming.

Of course, my first approach was to replace the Ethernet cable with another one. This did not solve the problem.

Next, I made sure that all WiFi connections in my device, such as B. on my mobile devices, work normally. There are no problems with the WiFi.

Next I tried to connect my work laptop to the same socket that the desktop computer used. I disabled the WiFi connection to the laptop to prevent switching if the signal fails. However, there were no problems using the laptop in the same socket that the desktop computer used.

I have a second wall outlet in my home office area, so I tried to take the desktop I was working on and connect to it. It gets interesting here. The desktop computer had no problems with this connector. In fact, I have been able to play an online game without interruption for a significant amount of time. Granted, the monitor in my home office is not in HD, so the download bandwidth requirements may be lower. However, they would still have been important and when I put them in the first socket there were still problems, even if no user programs were active.

I tried running the laptop on the first socket and the desktop on the second socket to see if the Windows Event Viewer detected disconnections but none were received on both computers.

Finally, I tried to connect the laptop to the first socket and to power it via the same power strip as the desktop computer with the desktop computer and its peripheral devices (speakers, external sound) (amplifier, monitor) all run at the same time. However, the event viewer did not find any connection problems with the laptop via the first socket, nor was it switched to battery power.

To summarize this problem JUST occurs with the desktop computer, and JUST occurs with this one particular jack.

That puts me in a kind of catch-22. I can't bring the desktop to the store (there is still a guarantee) and claim that there is something wrong with the ethernet card as it indicates that it is working properly in another socket. I cannot call my ISP because they indicate that the WiFi works, as well as the first socket with a laptop and the second socket with both computers. I can't get my building to look at it because they indicate that the jack with the laptop is working properly.

Any suggestions would be appreciated. Follow directions.

Desktop computer

Aeon 1080 Gaming Tower, Intel Core i7-7700, 3.6 GHz Quad-Core, 8 GB DDR4, 1 SSD with 240 GB and 1 hard disk with 1 TB, RealTek PCIe GbE family controller, Windows 10 Home 64 bit

Laptop

Lenovo ThinkPad, Intel Core i5-8250U 1.60 GHz, 8 GB RAM, 256 GB SSD, RealTek PCIe GbE controller, Windows 10 Pro 64 bit

internet – The WiFi connection of the Xiaomi laptop disappears after the restart

I will do my best to explain this problem. I recently bought a new laptop, one xiaomi per laptop in December. I'm not sure if this matters because the same problem has occurred with my Acer laptop. However, what happens is:

I have successfully installed Ubuntu 19.10 on both computers. The Acer has been running since April 16. After a few restarts, WLAN and Ethernet no longer work. Under settings> wifi it says that I have no WLAN drivers installed. It’s very frustrating. I use my laptop for development and this problem has thrown me into a loop twice lately. Every time I reinstall Ubuntu and the WiFi works magically (as well as Ethernet, although I don't have Ethernet to use atm. But having no connectivity at all means I have no way of installing drivers or anything ….).

I also have no ifconfig installed, it goes figure, apparently does not come in 19.10.

I really like 19.10, but this problem is becoming unbearable. Any suggestions for the next steps, tests and results are welcome. I will update this post with more information.

gameserver – I made a server-client-TCP connection, but this only works if the server and client are on the same computer. Any ideas?

So I want to start by being an absolute beginner in networking.

I create a game in C ++ and use SFML for networking (both the server and the client are in C ++, SFML). And I successfully created a server-client connection so I can send packets from one to the other. However, this only works if the server and the client are on the same computer (or on the same Internet connection (router)).

What I want to achieve is a server on my computer that can connect to my friends (who are not on the same router) after starting.

I tried to forward the port I'm using from the PC the server is running on, but it doesn't seem to work.

Any ideas?

Network – A connection to openvpn outside of the LAN cannot be established

I am trying to host an OpenVPN server on my Jetson nano board (arm64). I followed the tutorial from a digital ocean side, but I can't connect to my VPN server outside of the network. However, I can connect when I'm inside, even if I use noips ddns. I also forwarded the port on my router.

Even if I run tcpdump -i eth0 -vv -s 1500 port 1194 I don't see any connection either.

This is my client.ovpn (of course I removed the certificate and key details)

# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client

;dev tap
dev tun

;dev-node MyTap

;proto tcp
proto udp

remote example.ddns.net 1194
;remote my-server-2 1194

;remote-random

resolv-retry infinite

nobind

user nobody
group nogroup

# Try to preserve some state across restarts.
persist-key
persist-tun

;http-proxy-retry # retry on connection failures
;http-proxy (proxy server) (proxy port #)

#ca ca.crt
#cert client.crt
#key client.key

remote-cert-tls server

#tls-auth ta.key 1

cipher AES-256-CBC
auth SHA256
key-direction 1

#comp-lzo

verb 3

;mute 20

# script-security 2
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf

-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----



-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----


-----BEGIN PRIVATE KEY-----

-----END PRIVATE KEY-----




-----BEGIN OpenVPN Static key V1-----

-----END OpenVPN Static key V1-----

Any help is appreciated. Thank you very much.

mac os x – 2013 – No connection to the MySQL server when & # 39; reading the initial communication package & # 39 ;, System error: 0 "Internal error / verification (no system error)"

I have this user in MySQL

+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+

I want to connect remotely from my Mac using SSH

I can not connect. I got on

2013 – Broken connection to the MySQL server while & # 39; reading the initial communication package & # 39;, system error: 0 "Internal error / verification (no system error)"

I know if I added this record below

| root             | % |

I will be able to connect, but it does not seem to be very safe to do so.

I thought we could connect to our database via SSH.

Please correct me for what I did wrong.

PHP authorization error in connection with MySQL Centos 7.0.1406

  1. Error shows which side is not working. Error 505

This is resolved by typing the following in the PHP code to indicate the error. It can also be configured in the php.ini in the php configuration.

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
  1. Permission denied error

Enter image description here

This is resolved by entering the following on the server

(root @ localhost) # setsebool -P httpd_can_network_connect 1
(root @ localhost) # setsebool -P httpd_can_network_connect_db 1
  1. Error does not connect directly to IP 192.168.x.x, but it connects to "localhost"
    Enter image description here