mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
Refactor properties bootup, remove GlobalProperties and allow ServerConfig.loadFromProperties()
This commit is contained in:
1 parent
fe65a0ccb9
commit
370267ab6f
105 files changed
+3772
-3963
No files matched your search
@@ -1,49 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessage;
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessageList;
|
||||
|
||||
public class IndexEvent {
|
||||
|
||||
public static final int COMMIT_EVENT = 1;
|
||||
public static final int OPTIMISE_EVENT = 2;
|
||||
|
||||
private final int eventType;
|
||||
private final String indexName;
|
||||
|
||||
public IndexEvent(int eventType, String indexName) {
|
||||
this.eventType = eventType;
|
||||
this.indexName = indexName;
|
||||
}
|
||||
|
||||
public int getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public String getIndexName() {
|
||||
return indexName;
|
||||
}
|
||||
|
||||
public static IndexEvent readBinaryMessage(DataInput dataInput) throws IOException {
|
||||
|
||||
int eventType = dataInput.readInt();
|
||||
String indexName = dataInput.readUTF();
|
||||
return new IndexEvent(eventType, indexName);
|
||||
}
|
||||
|
||||
public void writeBinaryMessage(BinaryMessageList msgList) throws IOException {
|
||||
|
||||
BinaryMessage msg = new BinaryMessage(indexName.length()+10);
|
||||
DataOutputStream os = msg.getOs();
|
||||
os.writeInt(BinaryMessage.TYPE_INDEX);
|
||||
os.writeInt(eventType);
|
||||
os.writeUTF(indexName);
|
||||
|
||||
msgList.add(msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessage;
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessageList;
|
||||
|
||||
public class IndexInvalidate {
|
||||
|
||||
private final String indexName;
|
||||
|
||||
public IndexInvalidate(String indexName) {
|
||||
this.indexName = indexName;
|
||||
}
|
||||
|
||||
public String getIndexName() {
|
||||
return indexName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hc = IndexInvalidate.class.hashCode();
|
||||
hc = hc * 31 + indexName.hashCode();
|
||||
return hc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o){
|
||||
if (o instanceof IndexInvalidate == false){
|
||||
return false;
|
||||
}
|
||||
return indexName.equals(((IndexInvalidate)o).indexName);
|
||||
}
|
||||
|
||||
public static IndexInvalidate readBinaryMessage(DataInput dataInput) throws IOException {
|
||||
|
||||
|
||||
String indexName = dataInput.readUTF();
|
||||
return new IndexInvalidate(indexName);
|
||||
}
|
||||
|
||||
public void writeBinaryMessage(BinaryMessageList msgList) throws IOException {
|
||||
|
||||
BinaryMessage msg = new BinaryMessage(indexName.length()+10);
|
||||
DataOutputStream os = msg.getOs();
|
||||
os.writeInt(BinaryMessage.TYPE_INDEX_INVALIDATE);
|
||||
os.writeUTF(indexName);
|
||||
|
||||
msgList.add(msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.api.TransactionEvent;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventBeans;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
@@ -14,6 +10,8 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Performs post commit processing using a background thread.
|
||||
* <p>
|
||||
@@ -36,8 +34,6 @@ public final class PostCommitProcessing {
|
||||
|
||||
private final BeanPersistIdMap beanPersistIdMap;
|
||||
|
||||
// private final BeanDeltaMap beanDeltaMap;
|
||||
|
||||
private final RemoteTransactionEvent remoteTransactionEvent;
|
||||
|
||||
private final DeleteByIdMap deleteByIdMap;
|
||||
@@ -45,7 +41,7 @@ public final class PostCommitProcessing {
|
||||
/**
|
||||
* Create for a TransactionManager and event.
|
||||
*/
|
||||
public PostCommitProcessing(ClusterManager clusterManager, TransactionManager manager, SpiTransaction transaction, TransactionEvent event) {
|
||||
public PostCommitProcessing(ClusterManager clusterManager, TransactionManager manager, TransactionEvent event) {
|
||||
|
||||
this.clusterManager = clusterManager;
|
||||
this.manager = manager;
|
||||
@@ -53,10 +49,7 @@ public final class PostCommitProcessing {
|
||||
this.event = event;
|
||||
this.deleteByIdMap = event.getDeleteByIdMap();
|
||||
this.persistBeanRequests = createPersistBeanRequests();
|
||||
|
||||
this.beanPersistIdMap = createBeanPersistIdMap();
|
||||
//this.beanDeltaMap = new BeanDeltaMap(event.getBeanDeltas());
|
||||
|
||||
this.remoteTransactionEvent = createRemoteTransactionEvent();
|
||||
}
|
||||
|
||||
@@ -87,8 +80,8 @@ public final class PostCommitProcessing {
|
||||
public void notifyCluster() {
|
||||
if (remoteTransactionEvent != null && !remoteTransactionEvent.isEmpty()) {
|
||||
// send the interesting events to the cluster
|
||||
if (manager.getClusterDebugLevel() > 0 || logger.isDebugEnabled()) {
|
||||
logger.info("Cluster Send: " + remoteTransactionEvent.toString());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Cluster Send: {}", remoteTransactionEvent);
|
||||
}
|
||||
|
||||
clusterManager.broadcast(remoteTransactionEvent);
|
||||
@@ -147,12 +140,6 @@ public final class PostCommitProcessing {
|
||||
|
||||
RemoteTransactionEvent remoteTransactionEvent = new RemoteTransactionEvent(serverName);
|
||||
|
||||
// if (beanDeltaMap != null) {
|
||||
// for (BeanDeltaList deltaList : beanDeltaMap.deltaLists()) {
|
||||
// remoteTransactionEvent.addBeanDeltaList(deltaList);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (beanPersistIdMap != null) {
|
||||
for (BeanPersistIds beanPersist : beanPersistIdMap.values()) {
|
||||
remoteTransactionEvent.addBeanPersistIds(beanPersist);
|
||||
@@ -170,13 +157,6 @@ public final class PostCommitProcessing {
|
||||
}
|
||||
}
|
||||
|
||||
Set<IndexInvalidate> indexInvalidations = event.getIndexInvalidations();
|
||||
if (indexInvalidations != null) {
|
||||
for (IndexInvalidate indexInvalidate : indexInvalidations) {
|
||||
remoteTransactionEvent.addIndexInvalidate(indexInvalidate);
|
||||
}
|
||||
}
|
||||
|
||||
return remoteTransactionEvent;
|
||||
}
|
||||
|
||||
|
||||
+4
-44
@@ -1,15 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable.TableIUD;
|
||||
import com.avaje.ebeaninternal.server.cluster.BinaryMessageList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoteTransactionEvent implements Runnable {
|
||||
|
||||
private List<BeanPersistIds> beanPersistList = new ArrayList<BeanPersistIds>();
|
||||
@@ -19,10 +17,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
private List<BeanDeltaList> beanDeltaLists;
|
||||
|
||||
private BeanDeltaMap beanDeltaMap;
|
||||
|
||||
private List<IndexEvent> indexEventList;
|
||||
|
||||
private Set<IndexInvalidate> indexInvalidations;
|
||||
|
||||
private DeleteByIdMap deleteByIdMap;
|
||||
|
||||
@@ -56,12 +50,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
|
||||
public void writeBinaryMessage(BinaryMessageList msgList) throws IOException {
|
||||
|
||||
if (indexInvalidations != null){
|
||||
for (IndexInvalidate indexInvalidate : indexInvalidations) {
|
||||
indexInvalidate.writeBinaryMessage(msgList);
|
||||
}
|
||||
}
|
||||
|
||||
if (tableList != null){
|
||||
for (int i = 0; i < tableList.size(); i++) {
|
||||
tableList.get(i).writeBinaryMessage(msgList);
|
||||
@@ -85,12 +73,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
beanDeltaLists.get(i).writeBinaryMessage(msgList);
|
||||
}
|
||||
}
|
||||
|
||||
if (indexEventList != null){
|
||||
for (int i = 0; i < indexEventList.size(); i++) {
|
||||
indexEventList.get(i).writeBinaryMessage(msgList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
@@ -101,13 +83,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
beanPersistList.add(beanPersist);
|
||||
}
|
||||
|
||||
public void addIndexInvalidate(IndexInvalidate indexInvalidate){
|
||||
if (indexInvalidations == null){
|
||||
indexInvalidations = new HashSet<IndexInvalidate>();
|
||||
}
|
||||
indexInvalidations.add(indexInvalidate);
|
||||
}
|
||||
|
||||
public void addTableIUD(TableIUD tableIud){
|
||||
if (tableList == null){
|
||||
tableList = new ArrayList<TableIUD>(4);
|
||||
@@ -129,13 +104,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
beanDeltaMap.addBeanDelta(beanDelta);
|
||||
}
|
||||
|
||||
public void addIndexEvent(IndexEvent indexEvent){
|
||||
if (indexEventList == null){
|
||||
indexEventList = new ArrayList<IndexEvent>(2);
|
||||
}
|
||||
indexEventList.add(indexEvent);
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
@@ -156,14 +124,6 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
this.deleteByIdMap = deleteByIdMap;
|
||||
}
|
||||
|
||||
public Set<IndexInvalidate> getIndexInvalidations() {
|
||||
return indexInvalidations;
|
||||
}
|
||||
|
||||
public List<IndexEvent> getIndexEventList() {
|
||||
return indexEventList;
|
||||
}
|
||||
|
||||
public List<TableIUD> getTableIUDList() {
|
||||
return tableList;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.BackgroundExecutor;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.event.TransactionEventListener;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
@@ -24,6 +11,16 @@ import com.avaje.ebeaninternal.server.cluster.ClusterManager;
|
||||
import com.avaje.ebeaninternal.server.core.BootupClasses;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
import com.avaje.ebeaninternal.server.lib.sql.DataSourcePool;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* Manages transactions.
|
||||
@@ -97,8 +94,6 @@ public class TransactionManager {
|
||||
* Id's for transaction logging.
|
||||
*/
|
||||
protected AtomicLong transactionCounter = new AtomicLong(1000);
|
||||
|
||||
protected int clusterDebugLevel;
|
||||
|
||||
protected final BulkEventListenerMap bulkEventListenerMap;
|
||||
|
||||
@@ -119,16 +114,12 @@ public class TransactionManager {
|
||||
|
||||
List<TransactionEventListener> transactionEventListeners = bootupClasses.getTransactionEventListeners();
|
||||
this.transactionEventListeners = transactionEventListeners.toArray(new TransactionEventListener[transactionEventListeners.size()]);
|
||||
|
||||
// log some transaction events using a java util logger
|
||||
this.clusterDebugLevel = GlobalProperties.getInt("ebean.cluster.debuglevel", 0);
|
||||
|
||||
|
||||
this.defaultBatchMode = config.isPersistBatching();
|
||||
this.prefix = "";
|
||||
this.externalTransPrefix = "e";
|
||||
|
||||
this.prefix = GlobalProperties.get("transaction.prefix", "");
|
||||
this.externalTransPrefix = GlobalProperties.get("transaction.prefix", "e");
|
||||
|
||||
String value = GlobalProperties.get("transaction.onqueryonly", "CLOSE").toUpperCase().trim();
|
||||
String value = System.getProperty("ebean.transaction.onqueryonly", "CLOSE").toUpperCase().trim();
|
||||
this.onQueryOnly = getOnQueryOnly(value, dataSource);
|
||||
|
||||
initialiseHeartbeat();
|
||||
@@ -219,20 +210,6 @@ public class TransactionManager {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cluster debug level.
|
||||
*/
|
||||
public int getClusterDebugLevel() {
|
||||
return clusterDebugLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cluster debug level.
|
||||
*/
|
||||
public void setClusterDebugLevel(int clusterDebugLevel) {
|
||||
this.clusterDebugLevel = clusterDebugLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the type of behavior to use when closing a transaction that was used to query data only.
|
||||
*/
|
||||
@@ -416,7 +393,7 @@ public class TransactionManager {
|
||||
TXN_LOGGER.debug(transaction.getLogPrefix()+"Commit");
|
||||
}
|
||||
|
||||
PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, transaction, transaction.getEvent());
|
||||
PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, transaction.getEvent());
|
||||
|
||||
postCommit.notifyLocalCacheIndex();
|
||||
postCommit.notifyCluster();
|
||||
@@ -445,7 +422,7 @@ public class TransactionManager {
|
||||
TransactionEvent event = new TransactionEvent();
|
||||
event.add(tableEvents);
|
||||
|
||||
PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, null, event);
|
||||
PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, event);
|
||||
|
||||
// invalidate parts of local cache and index
|
||||
postCommit.notifyLocalCacheIndex();
|
||||
@@ -458,8 +435,8 @@ public class TransactionManager {
|
||||
*/
|
||||
public void remoteTransactionEvent(RemoteTransactionEvent remoteEvent) {
|
||||
|
||||
if (clusterDebugLevel > 0 || logger.isDebugEnabled()) {
|
||||
logger.info("Cluster Received: " + remoteEvent.toString());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Cluster Received: " + remoteEvent.toString());
|
||||
}
|
||||
|
||||
List<TableIUD> tableIUDList = remoteEvent.getTableIUDList();
|
||||
|
||||
Reference in new issue
Block a user