Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsubscribe #112

Open
BrunoPGNatal opened this issue Aug 24, 2023 · 1 comment
Open

Unsubscribe #112

BrunoPGNatal opened this issue Aug 24, 2023 · 1 comment

Comments

@BrunoPGNatal
Copy link

  • SPADE version: 3.3.0
  • Python version: 3.11.4
  • Operating System: Windows 11 Home 64 bits

Description

I'm using the SPADE framework to automate the organization of mats. However, when I need to remove a transporter from the system, it's necessary to unsubscribe agents from the contact list. Unfortunately, I haven't been able to successfully unregister them using SPADE. I haven't found any method that addresses this particular requirement.

What I Did

I've developed a behavior that monitors incoming requests for subscription or unsubscription from the contact list. While the subscription part works smoothly, I'm facing issues with the unsubscription process.

class ConveyorBehCyclic(CyclicBehaviour):

def __int__(self):
    self._state = None

def on_subscribed(self, jid):
    print(f'The agent {self.agent.name} accepted the subscription from {jid.split("@")[0]}')

def on_unsubscribe(self, jid):
    print(f'The agent {jid.split("@")[0]} wasts to unsubscribe in the list of contacts')
    self.presence.approve(jid)

def on_subscribe(self, jid):
    print(f'The agent {jid.split("@")[0]} wants to subscribe in the list of contacts')
    self.presence.approve(jid)

async def on_start(self) -> None:
    print('register started')
    self._state = True  # Variable responsible to register once in contact list

async def on_end(self) -> None:
    print('register ended')

async def run(self) -> None:

    self.presence.on_subscribe = self.on_subscribe
    self.presence.on_subscribed = self.on_subscribed
    self.presence.on_unsubscribe = self.on_unsubscribe
   
    if self._state:
        with open("Jid's.txt", "r") as file:
            lines = file.readlines()

        for line in lines:
            jid = line.strip()
            if "JID" != jid:
                try:
                    self.presence.subscribe(jid)
                    print(f'Agent - [{self.agent.name}] - Sent a message register to [{jid}] ')
                except Exception as e:
                    print(f'Behaviour unexpected, cause {e}')

        self._state = False
    print('Register behaviour checked')

    await asyncio.sleep(10)
@0x1F602
Copy link

0x1F602 commented Sep 4, 2023

I've been having an issue with the auto accept subscribe code, wonder if there was a breaking change. On top of that my agents are holding onto their presence as available even after killing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants