class NewSubscriptionTask extends SubscriptionTask
{
    private static final Logger log = LoggerFactory.getLogger(NewSubscriptionTask.class);

    /**
     * This no-argument constructor is provided for serialization purposes. It should generally not be used otherwise.
     */
    public NewSubscriptionTask()
    {
    }

    /**
     * Constructs a new task that creates a subscription to a pubsub node.
     *
     * @param subscription The to-be-created subscription
     */
    public NewSubscriptionTask(@Nonnull final NodeSubscription subscription)
    {
        super(subscription);
    }

    @Override
    public void run()
    {<FILL_FUNCTION_BODY>}
}

        // Note: this implementation should apply changes in-memory state only. It explicitly needs not update
        // persisted data storage, as this can be expected to be done by the cluster node that issued this task.
        // Applying such changes in this task would, at best, needlessly require resources.
        log.debug("[TASK] New subscription : {}", toString());

        final Optional<PubSubService> optService = getServiceIfLoaded();
        final Optional<Node> optNode = getNodeIfLoaded();
        final Optional<NodeSubscription> optSubscription = getSubscriptionIfLoaded();

        // This will only occur if a PEP service is not loaded on this particular cluster node. We can safely do nothing
        // in this case since any changes that might have been applied here will also have been applied to the database
        // by the cluster node where this task originated, meaning that those changes get loaded from the database when
        // the pubsub node is retrieved from the database in the future (OF-2077)
        if (!optService.isPresent() || !optNode.isPresent() || !optSubscription.isPresent()) {
            return;
        }

        final PubSubService service = optService.get();
        final Node node = optNode.get();
        final NodeSubscription subscription = optSubscription.get();

        if (node.getAffiliate(getOwner()) == null)
        {
            // add the missing 'none' affiliation
            NodeAffiliate affiliate = new NodeAffiliate(node, getOwner());
            affiliate.setAffiliation(NodeAffiliate.Affiliation.none);
            node.addAffiliate(affiliate);
        }
        node.addSubscription(subscription);

        if (node.isPresenceBasedDelivery() && node.getSubscriptions(subscription.getOwner()).size() == 1)
        {
            if (subscription.getPresenceStates().isEmpty())
            {
                // Subscribe to the owner's presence since the node is only
                // sending events to online subscribers and this is the first
                // subscription of the user and the subscription is not
                // filtering notifications based on presence show values.
                service.presenceSubscriptionRequired(node, getOwner());
            }
        }
    
<methods>public void <init>() ,public void <init>(org.jivesoftware.openfire.pubsub.NodeSubscription) ,public JID getOwner() ,public org.jivesoftware.openfire.pubsub.NodeSubscription.State getState() ,public JID getSubscriberJid() ,public java.lang.String getSubscriptionId() ,public Optional<org.jivesoftware.openfire.pubsub.NodeSubscription> getSubscriptionIfLoaded() ,public void readExternal(java.io.ObjectInput) throws java.io.IOException, java.lang.ClassNotFoundException,public java.lang.String toString() ,public void writeExternal(java.io.ObjectOutput) throws java.io.IOException<variables>private JID owner,private org.jivesoftware.openfire.pubsub.NodeSubscription.State state,private java.lang.String subId,private JID subJid