All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.header.txt Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
/**
 * Licensed 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.
 */

// GENERATED CODE - PLEASE DO NOT EDIT

package ${packageName};

public final class JRoutine_${interfaceName}${genericTypes} implements ${interfaceFullName} {

    private final com.gh.bmd.jrt.common.WeakIdentityHashMap> mMutexMap;

    private final String mShareGroup;

    private final java.lang.ref.WeakReference<${classFullName}> mWrapped;

    public JRoutine_${interfaceName}(final ${classFullName} wrapped,
            final com.gh.bmd.jrt.common.WeakIdentityHashMap> mutexMap,
            final String shareGroup, final com.gh.bmd.jrt.builder.RoutineConfiguration configuration) {

        if (wrapped == null) {

            throw new NullPointerException("the wrapped instance must not be null");
        }

        if (mutexMap == null) {

            throw new NullPointerException("the mutex map must not be null");
        }

        mWrapped = new java.lang.ref.WeakReference<${classFullName}>(wrapped);
        mMutexMap = mutexMap;
        mShareGroup = (shareGroup != null) ? shareGroup : com.gh.bmd.jrt.annotation.Share.ALL;
        ${routineFieldsInit}
    }

    @javax.annotation.Nonnull
    public static com.gh.bmd.jrt.routine.WrapperBuilder<${interfaceFullName}> on(final ${classFullName} wrapped) {

        return new ${interfaceName}WrapperBuilder(wrapped);
    }

    private Object getMutex(final String shareGroup) {

        if (com.gh.bmd.jrt.annotation.Share.NONE.equals(shareGroup)) {

            return null;
        }

        synchronized (mMutexMap) {

            final ${classFullName} wrapped = mWrapped.get();

            if (wrapped == null) {

                throw new IllegalStateException("target object has been destroyed");
            }

            java.util.Map mutexMap = mMutexMap.get(wrapped);

            if (mutexMap == null) {

                mutexMap = new java.util.HashMap();
                mMutexMap.put(wrapped, mutexMap);
            }

            final String name = (shareGroup != null) ? shareGroup : mShareGroup;
            Object mutex = mutexMap.get(name);

            if (mutex == null) {

                mutex = new Object();
                mutexMap.put(name, mutex);
            }

            return mutex;
        }
    }

    private static class ${interfaceName}WrapperBuilder extends com.gh.bmd.jrt.routine.WrapperBuilder<${interfaceFullName}> {

        private final ${classFullName} mTarget;

        private final com.gh.bmd.jrt.common.ClassToken mToken = new com.gh.bmd.jrt.common.ClassToken<${interfaceFullName}>() {};

        private ${interfaceName}WrapperBuilder(final ${classFullName} target) {

            mTarget = target;
        }

        @javax.annotation.Nonnull
        @Override
        protected Object getTarget() {

            return mTarget;
        }

        @javax.annotation.Nonnull
        @Override
        protected Class<${interfaceFullName}> getWrapperClass() {

            return mToken.getRawClass();
        }

        @javax.annotation.Nonnull
        @Override
        protected ${interfaceFullName} newWrapper(
                @javax.annotation.Nonnull final com.gh.bmd.jrt.common.WeakIdentityHashMap> mutexMap,
                @javax.annotation.Nonnull final String shareGroup,
                @javax.annotation.Nonnull final com.gh.bmd.jrt.builder.RoutineConfiguration configuration) {

            return new JRoutine_${interfaceName}(mTarget, mutexMap, shareGroup, configuration);
        }
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy