class ResourceLock<T extends HasMetadata> implements Lock {

  private final ObjectMeta meta;
  private final String identity;
  private T resource;

  public ResourceLock(String namespace, String name, String identity) {
    this(new ObjectMetaBuilder().withNamespace(namespace).withName(name).build(), identity);
  }

  public ResourceLock(ObjectMeta meta, String identity) {
    this.meta = meta;
    Objects.requireNonNull(meta.getNamespace(), "namespace is required");
    Objects.requireNonNull(meta.getName(), "name is required");
    this.identity = Objects.requireNonNull(identity, "identity is required");
  }

  protected abstract Class<T> getKind();

  @Override
  public synchronized LeaderElectionRecord get(KubernetesClient client) {<FILL_FUNCTION_BODY>}

  @Override
  public synchronized void create(KubernetesClient client, LeaderElectionRecord leaderElectionRecord) {
    resource = client.resource(toResource(leaderElectionRecord, getObjectMeta(null))).create();
  }

  @Override
  public synchronized void update(KubernetesClient client, LeaderElectionRecord leaderElectionRecord) {
    Objects.requireNonNull(resource, "get or create must be called first");
    client.resource(toResource(leaderElectionRecord, getObjectMeta(resource.getMetadata().getResourceVersion())))
        .patch(PatchContext.of(PatchType.JSON_MERGE));
  }

  /**
   * Convert the record to a resource
   *
   * @param leaderElectionRecord
   * @param meta not null
   * @return
   */
  protected abstract T toResource(LeaderElectionRecord leaderElectionRecord, ObjectMetaBuilder meta);

  protected abstract LeaderElectionRecord toRecord(T resource);

  protected ObjectMetaBuilder getObjectMeta(String version) {
    return new ObjectMetaBuilder(meta).withResourceVersion(version);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String identity() {
    return identity;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String describe() {
    return String.format("%sLock: %s - %s (%s)", getKind().getSimpleName(), meta.getNamespace(), meta.getName(), identity);
  }

  void setResource(T resource) {
    this.resource = resource;
  }

}

    resource = client.resources(getKind()).inNamespace(meta.getNamespace()).withName(meta.getName()).get();
    if (resource != null) {
      return toRecord(resource);
    }
    return null;
  
<no_super_class>