-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from pcnfernando/dev
Support concurrent publishing at Email Sink
- Loading branch information
Showing
6 changed files
with
179 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...in/java/io/siddhi/extension/io/email/sink/transport/EmailClientConnectionPoolFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.siddhi.extension.io.email.sink.transport; | ||
|
||
import org.apache.commons.pool.BaseKeyedPoolableObjectFactory; | ||
import org.wso2.transport.email.contract.EmailClientConnector; | ||
import org.wso2.transport.email.contract.EmailConnectorFactory; | ||
import org.wso2.transport.email.exception.EmailConnectorException; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* The abstract class that needs to be implemented when supporting a new non-secure transport | ||
* to mainly create, validate and terminate the client to the endpoint. | ||
*/ | ||
public class EmailClientConnectionPoolFactory extends BaseKeyedPoolableObjectFactory { | ||
private EmailClientConnector emailClientConnector; | ||
|
||
public EmailClientConnectionPoolFactory(EmailConnectorFactory emailConnectorFactory, | ||
Map<String, String> clientProperties) throws EmailConnectorException { | ||
emailClientConnector = emailConnectorFactory.createEmailClientConnector(); | ||
emailClientConnector.init(clientProperties); | ||
} | ||
|
||
@Override | ||
public Object makeObject(Object key) throws EmailConnectorException { | ||
if (!emailClientConnector.isConnected()) { | ||
emailClientConnector.connect(); | ||
} | ||
return emailClientConnector; | ||
} | ||
|
||
@Override | ||
public boolean validateObject(Object key, Object obj) { | ||
return obj != null && ((EmailClientConnector) obj).isConnected(); | ||
} | ||
|
||
public void destroyObject(Object key, Object obj) { | ||
if (obj != null) { | ||
((EmailClientConnector) obj).disconnect(); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...in/java/io/siddhi/extension/io/email/sink/transport/EmailClientConnectionPoolManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.siddhi.extension.io.email.sink.transport; | ||
|
||
import io.siddhi.extension.io.email.util.EmailConstants; | ||
import org.apache.commons.pool.impl.GenericKeyedObjectPool; | ||
import org.wso2.transport.email.contract.EmailConnectorFactory; | ||
import org.wso2.transport.email.exception.EmailConnectorException; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This class is used hold the secure/non-secure connections for an Agent. | ||
*/ | ||
|
||
public class EmailClientConnectionPoolManager { | ||
private static GenericKeyedObjectPool connectionPool; | ||
|
||
public static synchronized void initializeConnectionPool(EmailConnectorFactory emailConnectorFactory, | ||
Map<String, String> clientProperties) throws EmailConnectorException { | ||
EmailClientConnectionPoolFactory emailClientConnectionPoolFactory | ||
= new EmailClientConnectionPoolFactory(emailConnectorFactory, clientProperties); | ||
if (connectionPool == null) { | ||
int poolSize = Integer.parseInt(clientProperties.get(EmailConstants.PUBLISHER_POOL_SIZE)); | ||
connectionPool = new GenericKeyedObjectPool(); | ||
connectionPool.setFactory(emailClientConnectionPoolFactory); | ||
connectionPool.setMaxTotal(poolSize); | ||
connectionPool.setMaxActive(poolSize); | ||
connectionPool.setTestOnBorrow(true); | ||
connectionPool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK); | ||
} | ||
} | ||
|
||
public static GenericKeyedObjectPool getConnectionPool() { | ||
return connectionPool; | ||
} | ||
|
||
public static void uninitializeConnectionPool() { | ||
connectionPool = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters