-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
305 additions
and
37 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
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
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
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
54 changes: 54 additions & 0 deletions
54
...les/container/src/main/java/org/mule/runtime/container/internal/util/CheckedSupplier.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,54 @@ | ||
/* | ||
* Copyright 2023 Salesforce, Inc. All rights reserved. | ||
* The software in this package is published under the terms of the CPAL v1.0 | ||
* license, a copy of which has been included with this distribution in the | ||
* LICENSE.txt file. | ||
*/ | ||
package org.mule.runtime.container.internal.util; | ||
|
||
import org.mule.runtime.api.exception.MuleRuntimeException; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* A {@link Supplier} which can throw exceptions | ||
* | ||
* @param <T> the generic type of the return value | ||
* @since 4.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface CheckedSupplier<T> extends Supplier<T> { | ||
|
||
@Override | ||
default T get() { | ||
try { | ||
return getChecked(); | ||
} catch (Throwable throwable) { | ||
return handleException(throwable); | ||
} | ||
} | ||
|
||
/** | ||
* Handles the {@code throwable} | ||
* | ||
* @param throwable the error that was caught | ||
*/ | ||
default T handleException(Throwable throwable) { | ||
throw propagate(throwable); | ||
} | ||
|
||
/** | ||
* Executes an unsafe operation | ||
* | ||
* @throws Exception if anything goes wrong | ||
*/ | ||
T getChecked() throws Throwable; | ||
|
||
public static RuntimeException propagate(Throwable t) { | ||
if (t instanceof RuntimeException) { | ||
return (RuntimeException) t; | ||
} else { | ||
return new MuleRuntimeException(t); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...s/container/src/main/java/org/mule/runtime/container/internal/util/OrderedProperties.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,58 @@ | ||
/* | ||
* Copyright 2023 Salesforce, Inc. All rights reserved. | ||
* The software in this package is published under the terms of the CPAL v1.0 | ||
* license, a copy of which has been included with this distribution in the | ||
* LICENSE.txt file. | ||
*/ | ||
package org.mule.runtime.container.internal.util; | ||
|
||
import java.util.Enumeration; | ||
import java.util.LinkedHashSet; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.Vector; | ||
|
||
import org.apache.commons.collections4.keyvalue.DefaultMapEntry; | ||
|
||
public class OrderedProperties extends Properties { | ||
|
||
private static final long serialVersionUID = -3611415251568805458L; | ||
|
||
private final Vector<Object> keys = new Vector<>(); | ||
|
||
@Override | ||
public Set<Map.Entry<Object, Object>> entrySet() { | ||
Set<Map.Entry<Object, Object>> entries = new LinkedHashSet<>(); | ||
Enumeration<?> keys = this.propertyNames(); | ||
|
||
while (keys.hasMoreElements()) { | ||
Object key = keys.nextElement(); | ||
entries.add(new DefaultMapEntry<>(key, this.getProperty((String) key))); | ||
} | ||
|
||
return entries; | ||
} | ||
|
||
@Override | ||
public Enumeration<?> propertyNames() { | ||
return this.keys.elements(); | ||
} | ||
|
||
@Override | ||
public Object put(Object key, Object value) { | ||
if (this.keys.contains(key)) { | ||
this.keys.remove(key); | ||
} | ||
|
||
this.keys.add(key); | ||
|
||
return super.put(key, value); | ||
} | ||
|
||
@Override | ||
public Object remove(Object key) { | ||
this.keys.remove(key); | ||
return super.remove(key); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ntainer/src/main/java/org/mule/runtime/container/internal/util/StandaloneServerUtils.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,62 @@ | ||
/* | ||
* Copyright 2023 Salesforce, Inc. All rights reserved. | ||
* The software in this package is published under the terms of the CPAL v1.0 | ||
* license, a copy of which has been included with this distribution in the | ||
* LICENSE.txt file. | ||
*/ | ||
package org.mule.runtime.container.internal.util; | ||
|
||
import static java.util.Optional.of; | ||
import static java.util.Optional.ofNullable; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Standalone server instance utility methods. | ||
* <p> | ||
* This utility methods are not meant to be used in container mode. | ||
* | ||
* @since 4.0 | ||
*/ | ||
public class StandaloneServerUtils { | ||
|
||
public static final String MULE_HOME_DIRECTORY_PROPERTY = "mule.home"; | ||
public static final String MULE_BASE_DIRECTORY_PROPERTY = "mule.base"; | ||
|
||
/** | ||
* @return the MULE_HOME directory of this instance. Returns null if the property is not set | ||
*/ | ||
public static Optional<File> getMuleHome() { | ||
final String muleHome = System.getProperty(MULE_HOME_DIRECTORY_PROPERTY); | ||
return ofNullable(muleHome != null ? new File(muleHome) : null); | ||
} | ||
|
||
/** | ||
* The mule runtime base folder is a directory similar to the mule runtime installation one but with only the specific | ||
* configuration parts of the mule runtime installation such as the apps folder, the domain folder, the conf folder. | ||
* | ||
* @return the MULE_BASE directory of this instance. Returns the | ||
* {@link org.mule.runtime.core.api.config.MuleProperties#MULE_HOME_DIRECTORY_PROPERTY} property value if | ||
* {@link org.mule.runtime.core.api.config.MuleProperties#MULE_BASE_DIRECTORY_PROPERTY} is not set which may be null. | ||
*/ | ||
public static Optional<File> getMuleBase() { | ||
Optional<File> muleBase = null; | ||
String muleBaseVar = System.getProperty(MULE_BASE_DIRECTORY_PROPERTY); | ||
|
||
if (muleBaseVar != null && !muleBaseVar.trim().equals("") && !muleBaseVar.equals("%MULE_BASE%")) { | ||
try { | ||
muleBase = of(new File(muleBaseVar).getCanonicalFile()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
if (muleBase == null) { | ||
muleBase = getMuleHome(); | ||
} | ||
return muleBase; | ||
} | ||
|
||
} |
Oops, something went wrong.