Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce `functioncache` and `functioncontainer` - introduce `functioncache` for managing function dependencies (e.g. setting up function class loader and its classpath). The `functioncache` is shared across multiple instances. - introduce `functioncontainer` for providing a runtime environment to invoke functions. - provide a thread based `functioncontainer` implementation, which uses functioncache to load classpath and initial its function class loader. * Revert FunctionID/InstanceID to String * Add test cases for functioncache and functioncontainer
- Loading branch information
Showing
32 changed files
with
1,675 additions
and
6 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
41 changes: 41 additions & 0 deletions
41
pulsar-functions/src/main/java/org/apache/pulsar/functions/runtime/FunctionID.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,41 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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 org.apache.pulsar.functions.runtime; | ||
|
||
/** | ||
* A identifier for a function. | ||
*/ | ||
public class FunctionID extends UUID { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public FunctionID() { | ||
super(); | ||
} | ||
|
||
public FunctionID(long lowestBits, long highestBits) { | ||
super(lowestBits, highestBits); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "fn-" + super.toString(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
pulsar-functions/src/main/java/org/apache/pulsar/functions/runtime/InstanceID.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,43 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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 org.apache.pulsar.functions.runtime; | ||
|
||
/** | ||
* Unique identifier for an execution of a function. | ||
*/ | ||
public class InstanceID extends UUID { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public static final InstanceID INVALID_INSTANCE_ID = new InstanceID(-1L, -1L); | ||
|
||
public InstanceID() { | ||
super(); | ||
} | ||
|
||
public InstanceID(long lowestBits, long highestBits) { | ||
super(lowestBits, highestBits); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "instance-" + super.toString(); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
pulsar-functions/src/main/java/org/apache/pulsar/functions/runtime/UUID.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,65 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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 org.apache.pulsar.functions.runtime; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* A identifier for an object. | ||
*/ | ||
public class UUID implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final java.util.UUID uuid; | ||
|
||
public UUID() { | ||
this.uuid = java.util.UUID.randomUUID(); | ||
} | ||
|
||
public UUID(long mostSigBits, long leastSigBits) { | ||
this.uuid = new java.util.UUID(mostSigBits, leastSigBits); | ||
} | ||
|
||
@VisibleForTesting | ||
java.util.UUID getInternalUUID() { | ||
return uuid; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return uuid.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof UUID)) { | ||
return false; | ||
} | ||
UUID another = (UUID) obj; | ||
return uuid.equals(another.uuid); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return uuid.toString(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
.../java/org/apache/pulsar/functions/runtime/container/AbstractFunctionContainerFactory.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,41 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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 org.apache.pulsar.functions.runtime.container; | ||
|
||
import org.apache.pulsar.functions.runtime.functioncache.FunctionCacheManager; | ||
import org.apache.pulsar.functions.runtime.functioncache.FunctionCacheManagerImpl; | ||
|
||
/** | ||
* An abstract implementation of {@link FunctionContainerFactory}. | ||
*/ | ||
public abstract class AbstractFunctionContainerFactory implements FunctionContainerFactory { | ||
|
||
protected final FunctionCacheManager fnCache; | ||
|
||
protected AbstractFunctionContainerFactory() { | ||
this.fnCache = new FunctionCacheManagerImpl(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
fnCache.close(); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...ctions/src/main/java/org/apache/pulsar/functions/runtime/container/FunctionContainer.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,33 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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 org.apache.pulsar.functions.runtime.container; | ||
|
||
/** | ||
* A function container is an environment for invoking functions. | ||
*/ | ||
public interface FunctionContainer { | ||
|
||
void start() throws Exception; | ||
|
||
void join() throws InterruptedException; | ||
|
||
void stop(); | ||
|
||
} |
Oops, something went wrong.